home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / VECTOR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  47.0 KB  |  1,520 lines

  1. #ifndef __VECTOR_H
  2. #define __VECTOR_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. /***************************************************************************
  6.  *
  7.  * vector - declarations for the Standard Library vector 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.  * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
  26.  * ALL RIGHTS RESERVED
  27.  *
  28.  * The software and information contained herein are proprietary to, and
  29.  * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
  30.  * intends to preserve as trade secrets such software and information.
  31.  * This software is furnished pursuant to a written license agreement and
  32.  * may be used, copied, transmitted, and stored only in accordance with
  33.  * the terms of such license and with the inclusion of the above copyright
  34.  * notice.  This software and information or any other copies thereof may
  35.  * not be provided or otherwise made available to any other person.
  36.  *
  37.  * Notwithstanding any other lease or license that may pertain to, or
  38.  * accompany the delivery of, this computer software and information, the
  39.  * rights of the Government regarding its use, reproduction and disclosure
  40.  * are as set forth in Section 52.227-19 of the FARS Computer
  41.  * Software-Restricted Rights clause.
  42.  * 
  43.  * Use, duplication, or disclosure by the Government is subject to
  44.  * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
  45.  * Technical Data and Computer Software clause at DFARS 252.227-7013.
  46.  * Contractor/Manufacturer is Rogue Wave Software, Inc.,
  47.  * P.O. Box 2328, Corvallis, Oregon 97339.
  48.  *
  49.  * This computer software and information is distributed with "restricted
  50.  * rights."  Use, duplication or disclosure is subject to restrictions as
  51.  * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
  52.  * Computer Software-Restricted Rights (April 1985)."  If the Clause at
  53.  * 18-52.227-74 "Rights in Data General" is specified in the contract,
  54.  * then the "Alternate III" clause applies.
  55.  *
  56.  **************************************************************************/
  57.  
  58. #ifndef __STD_VECTOR__
  59. #define __STD_VECTOR__
  60.  
  61. #include <stdcomp.h>
  62. #include <rw/stddefs.h> 
  63.  
  64. #include <algorithm>
  65. #include <iterator>
  66. #include <memory>
  67. #include <stdexcept>
  68.  
  69. #ifndef vector
  70. #define vector vector
  71. #endif
  72.  
  73. #ifndef _RWSTD_NO_NAMESPACE
  74. namespace std {
  75. #endif
  76.  
  77. //
  78. // Note that _RWSTD_COMPLEX_DEFAULT(x)
  79. // will expand to: ' = x', or nothing,
  80. // depending on your compiler's capabilities and/or
  81. // flag settings (see stdcomp.h).
  82. //
  83.   template <class T, class Allocator _RWSTD_COMPLEX_DEFAULT(allocator<T>) >
  84.   class vector
  85.   {
  86.  
  87.   private:
  88. #ifdef _RWSTD_ALLOCATOR
  89.     typedef _TYPENAME Allocator::template rebind<T>::other __value_alloc_type;
  90. #else
  91.     typedef allocator_interface<Allocator,T> __value_alloc_type;
  92. #endif
  93.  
  94.   public:
  95.     //
  96.     // Types.
  97.     //
  98.     typedef T                                          value_type;
  99.     typedef Allocator                                  allocator_type;
  100.  
  101. #ifndef _RWSTD_NO_COMPLICATED_TYPEDEF
  102.     typedef _TYPENAME _RWSTD_ALLOC_SIZE_TYPE               size_type;
  103.     typedef _TYPENAME _RWSTD_ALLOC_DIFF_TYPE               difference_type;
  104.     typedef _TYPENAME __value_alloc_type::pointer          iterator;
  105.     typedef _TYPENAME __value_alloc_type::const_pointer    const_iterator;
  106.     typedef _TYPENAME __value_alloc_type::reference        reference;
  107.     typedef _TYPENAME __value_alloc_type::const_reference  const_reference;
  108.     typedef _TYPENAME __value_alloc_type::pointer          pointer;
  109.     typedef _TYPENAME __value_alloc_type::const_pointer    const_pointer;
  110. #else
  111.     typedef size_t          size_type;
  112.     typedef ptrdiff_t       difference_type;
  113.     typedef T*              iterator;
  114.     typedef const T*        const_iterator;
  115.     typedef T&              reference;
  116.     typedef const T&        const_reference;
  117.     typedef T*              pointer;
  118.     typedef const T*        const_pointer;
  119. #endif  //_RWSTD_NO_COMPLICATED_TYPEDEF
  120.  
  121. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC 
  122.     typedef _RW_STD::reverse_iterator<const_iterator> const_reverse_iterator;
  123.     typedef _RW_STD::reverse_iterator<iterator>  reverse_iterator;
  124. #else
  125.     typedef _RW_STD::reverse_iterator<const_iterator, 
  126.       random_access_iterator_tag, value_type, 
  127.       const_reference, const_pointer, difference_type>
  128.       const_reverse_iterator;
  129.     typedef _RW_STD::reverse_iterator<iterator, 
  130.       random_access_iterator_tag, value_type,
  131.       reference, pointer, difference_type>
  132.       reverse_iterator;
  133. #endif
  134.  
  135. protected:
  136.  
  137.     size_type          __buffer_size;
  138.     iterator           __start;
  139.     iterator           __finish;
  140.     __RWSTD::__rw_basis<iterator,allocator_type>  __end_of_storage;
  141.  
  142.     void __insert_aux (iterator position, const T& x);
  143.     void __insert_aux (iterator position, size_type n, const T& x);
  144.  
  145.     void __destroy(iterator start, iterator finish)
  146.     {
  147.       while ( start != finish)
  148.         __value_alloc_type(__end_of_storage).destroy(start++);
  149.     }
  150.  
  151.     // 
  152.     //  Allocate buffers and fill with n values
  153.     //
  154.     void __init_n(size_type n, const T& value)
  155.     {
  156.       __init();
  157.       __start = __value_alloc_type(__end_of_storage).allocate(n,0);
  158. #ifndef _RWSTD_NO_EXCEPTIONS
  159.       try {
  160.         uninitialized_fill_n(__start, n, value);
  161.       } catch(...) {
  162.         __value_alloc_type(__end_of_storage).deallocate(__start,n);
  163.         throw;
  164.       }      
  165. #else
  166.       uninitialized_fill_n(__start, n, value);
  167. #endif // _RWSTD_NO_EXCEPTIONS
  168.       __finish = __start + n;
  169.       __end_of_storage = __finish;
  170.     } 
  171.  
  172.     void __init() 
  173.     {
  174.       __buffer_size = 
  175.       max((size_type)1,__RWSTD::__rw_allocation_size((value_type*)0,(size_type)0,(size_type)0));
  176.     }
  177.   public:
  178.     //
  179.     // construct/copy/destroy
  180.     //
  181.     _EXPLICIT vector (const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator())) 
  182.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  183.     { 
  184.       __init(); 
  185.     }
  186.  
  187. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  188.     vector (void) 
  189.       : __start(0), __finish(0), __end_of_storage(0,Allocator())
  190.     { ; }
  191.  
  192.     vector (size_type n, const T& value) 
  193.       : __start(0), __finish(0), __end_of_storage(0,Allocator())
  194.     {
  195.       __init_n(n,value);
  196.     }
  197. #endif
  198.  
  199.     _EXPLICIT vector (size_type n)
  200.       : __start(0), __finish(0), __end_of_storage(0,Allocator())
  201.     {
  202.       T value = T();
  203.       __init_n(n,value);
  204.     }
  205.  
  206. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  207.     template<class InputIterator>
  208.     vector (InputIterator first, InputIterator last,
  209.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  210.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  211.     {
  212.       size_type n;
  213.       __init(); 
  214.       __initialize(n, size_type(0));
  215.       distance(first, last, n);
  216.       __start = __value_alloc_type(__end_of_storage).allocate(n,0);
  217. #ifndef _RWSTD_NO_EXCEPTIONS
  218.       try {
  219.         __finish = uninitialized_copy(first, last, __start);
  220.       } catch(...) {
  221.         __value_alloc_type(__end_of_storage).deallocate(__start,n);
  222.         throw;
  223.       }      
  224. #else
  225.       __finish = uninitialized_copy(first, last, __start);
  226. #endif // _RWSTD_NO_EXCEPTIONS
  227.       __end_of_storage = __finish;
  228.     }
  229.     vector (int n, const T& value,
  230.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  231.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  232.     { __init_n((size_type)n,value); }
  233.     vector (unsigned int n, const T& value,
  234.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  235.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  236.     { __init_n((size_type)n,value); }
  237.     vector (long n, const T& value,
  238.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  239.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  240.     { __init_n((size_type)n,value); }
  241.     vector (unsigned long n, const T& value,
  242.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  243.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  244.     { __init_n((size_type)n,value); }
  245.     vector (short n, const T& value,
  246.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  247.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  248.     { __init_n((size_type)n,value); }
  249.     vector (unsigned short n, const T& value,
  250.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  251.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  252.     { __init_n((size_type)n,value); }
  253.     vector (char n, const T& value,
  254.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  255.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  256.     { __init_n((size_type)n,value); }
  257.     vector (unsigned char n, const T& value,
  258.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  259.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  260.     { __init_n((size_type)n,value); }
  261. #ifndef _RWSTD_NO_BOOL
  262.     vector (bool n, const T& value,
  263.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  264.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  265.     { __init_n((size_type)n,value); }
  266. #endif
  267. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  268.     vector (wchar_t n, const T& value,
  269.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  270.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  271.     { __init_n((size_type)n,value); }
  272. #endif
  273. #else
  274.     //
  275.     // Build a vector of size n with each element set to copy of value.
  276.     //
  277.     vector (size_type n, const T& value,
  278.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  279.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  280.     {
  281.       __init_n(n,value);
  282.     }
  283.  
  284.     vector (const_iterator first, const_iterator last,
  285.             const Allocator& alloc _RWSTD_DEFAULT_ARG(Allocator()))
  286.       : __start(0), __finish(0), __end_of_storage(0,alloc)
  287.     {
  288.       size_type n;
  289.       __init(); 
  290.       __initialize(n, size_type(0));
  291.       distance(first, last, n);
  292.       __start = __value_alloc_type(__end_of_storage).allocate(n,0);
  293. #ifndef _RWSTD_NO_EXCEPTIONS
  294.       try {
  295.         __finish = uninitialized_copy(first, last, __start);
  296.       } catch(...) {
  297.         __value_alloc_type(__end_of_storage).deallocate(__start,n);
  298.         throw;
  299.       }      
  300. #else
  301.       __finish = uninitialized_copy(first, last, __start);
  302. #endif // _RWSTD_NO_EXCEPTIONS
  303.       __end_of_storage = __finish;
  304.     }
  305.  
  306. #ifdef _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  307.     vector (const_iterator first, const_iterator last)
  308.       : __start(0), __finish(0), __end_of_storage(0,Allocator())
  309.     {
  310.       size_type n;
  311.       __init(); 
  312.       __initialize(n, size_type(0));
  313.       distance(first, last, n);
  314.       __start = __value_alloc_type(__end_of_storage).allocate(n,0);
  315. #ifndef _RWSTD_NO_EXCEPTIONS
  316.       try {
  317.         __finish = uninitialized_copy(first, last, __start);
  318.       } catch(...) {
  319.         __value_alloc_type(__end_of_storage).deallocate(__start,n);
  320.         throw;
  321.       }      
  322. #else
  323.       __finish = uninitialized_copy(first, last, __start);
  324. #endif //  _RWSTD_NO_EXCEPTIONS
  325.       __end_of_storage = __finish;
  326.     }
  327. #endif // _RWSTD_NO_DEFAULT_TEMPLATE_ARGS
  328. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  329.  
  330.     vector (const vector<T,Allocator>& x)
  331.       : __start(0), __finish(0), __end_of_storage(0,x.get_allocator())
  332.     {
  333.       __init(); 
  334.       __start = __value_alloc_type(__end_of_storage).allocate(x.end() - x.begin(),0);
  335.       __finish = uninitialized_copy(x.begin(), x.end(), __start);
  336.       __end_of_storage = __finish;
  337.     }
  338.  
  339.     ~vector ()
  340.     { 
  341.       __destroy(__start, __finish); 
  342.       __value_alloc_type(__end_of_storage).deallocate(__start,__end_of_storage.data()-__start);
  343.     }
  344.  
  345.     vector<T,Allocator>& operator= (const vector<T,Allocator>& x);
  346.  
  347. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  348.     template<class InputIterator> 
  349.     void assign (InputIterator first, InputIterator last)
  350.     { erase(begin(), end()); insert(begin(), first, last);  }
  351.     void assign (int n, T t)
  352.     { erase(begin(), end()); insert(begin(), n, t); }
  353.     void assign (unsigned int n, T t)
  354.     { erase(begin(), end()); insert(begin(), n, t); }
  355.     void assign (long n, T t)
  356.     { erase(begin(), end()); insert(begin(), n, t); }
  357.     void assign (unsigned long n, T t)
  358.     { erase(begin(), end()); insert(begin(), n, t); }
  359.     void assign (short n, T t)
  360.     { erase(begin(), end()); insert(begin(), n, t); }
  361.     void assign (unsigned short n, T t)
  362.     { erase(begin(), end()); insert(begin(), n, t); }
  363.     void assign (char n, T t)
  364.     { erase(begin(), end()); insert(begin(), n, t); }
  365.     void assign (unsigned char n, T t)
  366.     { erase(begin(), end()); insert(begin(), n, t); }
  367. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  368.     void assign (wchar_t n, T t)
  369.     { erase(begin(), end()); insert(begin(), n, t); }
  370. #endif
  371. #ifndef _RWSTD_NO_BOOL
  372.     void assign (bool n, T t)
  373.     { erase(begin(), end()); insert(begin(), n, t); }
  374. #endif
  375. #else
  376.     void assign (const_iterator first, const_iterator last)
  377.     { erase(begin(), end()); insert(begin(), first, last); }
  378.     //
  379.     // Assign n copies of t to this vector.
  380.     //
  381.     void assign (size_type n, const T& t)
  382.     { erase(begin(), end()); insert(begin(), n, t); }
  383. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  384.  
  385.     allocator_type get_allocator() const
  386.     {
  387.       return (allocator_type)__end_of_storage;
  388.     }
  389.  
  390.     //
  391.     // Iterators.
  392.     //
  393.     iterator       begin ()       { return __start;  }
  394.     const_iterator begin () const { return __start;  }
  395.     iterator       end ()         { return __finish; }
  396.     const_iterator end ()   const { return __finish; }
  397.  
  398.     reverse_iterator rbegin ()
  399.     { 
  400.       reverse_iterator tmp(end()); return tmp;
  401.     }
  402.     const_reverse_iterator rbegin () const
  403.     { 
  404.       const_reverse_iterator tmp(end()); return tmp;
  405.     }
  406.     reverse_iterator rend ()
  407.     { 
  408.       reverse_iterator tmp(begin()); return tmp;
  409.     }
  410.     const_reverse_iterator rend () const
  411.     { 
  412.       const_reverse_iterator tmp(begin()); return tmp;
  413.     }
  414.  
  415.     //
  416.     // Capacity.
  417.     //
  418.     size_type size ()     const { return size_type(end() - begin()); }
  419.     size_type max_size () const { return __value_alloc_type(__end_of_storage).max_size();   }
  420.     void resize (size_type new_size);
  421.     void resize (size_type new_size, T value);
  422.  
  423.     size_type capacity () const { return size_type(__end_of_storage.data() - begin()); }
  424.     bool      empty ()    const { return begin() == end();                    }
  425.     void reserve (size_type n)
  426.     {
  427.       _RWSTD_THROW(n > max_size(), length_error,
  428.         __RWSTD::except_msg_string(__RWSTD::__rwse_InvalidSizeParam,
  429.           "vector::reserve(size_t)",n,max_size()).msgstr());
  430.  
  431.       if (capacity() < n)
  432.       {
  433.         __value_alloc_type va(__end_of_storage);
  434.         iterator tmp = va.allocate(n,__start);
  435. #ifndef _RWSTD_NO_EXCEPTIONS
  436.         try {
  437.           uninitialized_copy(begin(), end(), tmp);
  438.         } catch(...) {
  439.           __value_alloc_type(__end_of_storage).deallocate(tmp,n);
  440.           throw;
  441.         }
  442. #else
  443.         uninitialized_copy(begin(), end(), tmp);
  444. #endif // _RWSTD_NO_EXCEPTIONS
  445.         __destroy(__start, __finish);
  446.         va.deallocate(__start,__end_of_storage.data()-__start);
  447.         __finish = tmp + size();
  448.         __start = tmp;
  449.         __end_of_storage = begin() + n;
  450.       }
  451.     }
  452.  
  453.     //
  454.     // Element access.
  455.     //
  456.     reference       operator[] (size_type n)       
  457.     {
  458. #ifdef _RWSTD_BOUNDS_CHECKING
  459.       _RWSTD_THROW(n >= size(), out_of_range,
  460.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  461.           "vector::operator[](size_t)",n,size()).msgstr());
  462. #endif
  463.       return *(begin() + n);
  464.  
  465.     }
  466.   
  467.     const_reference operator[] (size_type n) const 
  468.     {
  469. #ifdef _RWSTD_BOUNDS_CHECKING
  470.       _RWSTD_THROW(n >= size(), out_of_range,
  471.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  472.           "vector::operator[](size_t) const",n,size()).msgstr());
  473. #endif
  474.       return *(begin() + n);
  475.     }
  476.   
  477.     reference       at (size_type n)               
  478.     { 
  479.       _RWSTD_THROW(n >= size(), out_of_range,
  480.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  481.           "vector:: at(size_t)",n,size()).msgstr());
  482.       return *(begin() + n); 
  483.     }
  484.     const_reference at (size_type n)  const 
  485.     { 
  486.       _RWSTD_THROW(n >= size(), out_of_range,
  487.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  488.           "vector:: at(size_t) const",n,size()).msgstr());
  489.       return *(begin() + n); 
  490.     }
  491.     reference       front ()                       { return *begin();       }
  492.     const_reference front ()                 const { return *begin();       }
  493.     reference       back ()                        { return *(end() - 1);   }
  494.     const_reference back ()                  const { return *(end() - 1);   }
  495.  
  496.     //
  497.     // Modifiers.
  498.     //
  499.     void push_back (const T& x)
  500.     {
  501.       if (__finish != __end_of_storage.data())
  502.       {
  503.         __value_alloc_type(__end_of_storage).construct(__finish, x); 
  504.         __finish++;
  505.       }
  506.       else
  507.         __insert_aux(end(), x);
  508.     }
  509.     void pop_back()
  510.     {
  511.       --__finish; 
  512.       __value_alloc_type(__end_of_storage).destroy(__finish);
  513.     }
  514.  
  515.     //
  516.     // Insert x at position.
  517.     //
  518.     iterator insert (iterator position, const T& x)
  519.     {
  520.       size_type n = position - begin();
  521.       if (__finish != __end_of_storage.data() && position == end())
  522.       {
  523.         __value_alloc_type(__end_of_storage).construct(__finish, x); __finish++;
  524.       }
  525.       else
  526.         __insert_aux(position, x);
  527.       return begin() + n;
  528.     }
  529.  
  530. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  531.     template<class InputIterator>
  532.     void insert (iterator position, InputIterator first,
  533.                  InputIterator last);
  534.     void insert (iterator position, int n, const T& value)
  535.     { __insert_aux(position,(size_type)n,value); }
  536.     void insert (iterator position, int n, int value) // RW_BUG: fix for bts-42473
  537.     { __insert_aux(position,(size_type)n,value); }
  538.  
  539.     void insert (iterator position, unsigned int n, const T& value)
  540.     { __insert_aux(position,(size_type)n,value); }
  541.     void insert (iterator position, unsigned int n, unsigned int value) // RW_BUG: fix for bts-42473
  542.     { __insert_aux(position,(size_type)n,value); }
  543.  
  544.     void insert (iterator position, long n, const T& value) // RW_BUG: forgot const &
  545.     { __insert_aux(position,(size_type)n,value); }
  546.     void insert (iterator position, long n, long value) // RW_BUG: fix for bts-42473
  547.     { __insert_aux(position,(size_type)n,value); }
  548.  
  549.     void insert (iterator position, unsigned long n, const T& value)
  550.     { __insert_aux(position,(size_type)n,value); }
  551.     void insert (iterator position, unsigned long n, unsigned long value) // RW_BUG: fix for bts-42473
  552.     { __insert_aux(position,(size_type)n,value); }
  553.  
  554.     void insert (iterator position, short n, const T& value)
  555.     { __insert_aux(position,(size_type)n,value); }
  556.     void insert (iterator position, short n, short value) // RW_BUG: fix for bts-42473
  557.     { __insert_aux(position,(size_type)n,value); }
  558.  
  559.     void insert (iterator position, unsigned short n, const T& value)
  560.     { __insert_aux(position,(size_type)n,value); }
  561.     void insert (iterator position, unsigned short n, unsigned short value)  // RW_BUG: fix for bts-42473
  562.     { __insert_aux(position,(size_type)n,value); }
  563.  
  564.     void insert (iterator position, char n, const T& value)
  565.     { __insert_aux(position,(size_type)n,value); }
  566.     void insert (iterator position, char n, char value) // RW_BUG: fix for bts-42473
  567.     { __insert_aux(position,(size_type)n,value); }
  568.  
  569.     void insert (iterator position, unsigned char n, const T& value)
  570.     { __insert_aux(position,(size_type)n,value); }
  571.     void insert (iterator position, unsigned char n, unsigned char value) // RW_BUG: fix for bts-42473
  572.     { __insert_aux(position,(size_type)n,value); }
  573.  
  574. #ifndef _RWSTD_NO_BOOL
  575.     void insert (iterator position, bool n, const T& value)
  576.     { __insert_aux(position,(size_type)n,value); }
  577.     void insert (iterator position, bool n, bool value) // RW_BUG: fix for bts-42473
  578.     { __insert_aux(position,(size_type)n,value); }
  579.  
  580. #endif
  581. #ifndef _RWSTD_NO_OVERLOAD_WCHAR
  582.     void insert (iterator position, wchar_t n, const T& value)
  583.     { __insert_aux(position,(size_type)n,value); }
  584.     void insert (iterator position, wchar_t n, wchar_t value) // RW_BUG: fix for bts-42473
  585.     { __insert_aux(position,(size_type)n,value); }
  586.  
  587. #endif
  588. #else
  589.     void insert (iterator position, size_type n, const T& x)
  590.     { __insert_aux(position,n,x); }
  591.     void insert (iterator position, const_iterator first, const_iterator last);
  592. #endif // _RWSTD_NO_MEMBER_TEMPLATES
  593.  
  594.     iterator erase (iterator position)
  595.     {
  596.       if (position + 1 != end())
  597.         copy(position + 1, end(), position);
  598.       --__finish;
  599.       __value_alloc_type(__end_of_storage).destroy(__finish);
  600.       return position;
  601.     }
  602.     iterator erase (iterator first, iterator last)
  603.     {
  604.       iterator i = copy(last, end(), first);
  605.       iterator tmp = __finish;
  606.       __finish = __finish - (last - first); 
  607.       __destroy(i, tmp);
  608.       return first;
  609.     }
  610.  
  611.     void swap (vector<T,Allocator>& x)
  612.     {
  613.       if((allocator_type)__end_of_storage==(allocator_type)x.__end_of_storage)
  614.       {
  615. #ifndef _RWSTD_NO_NAMESPACE
  616.         std::swap(__start, x.__start);
  617.         std::swap(__finish, x.__finish);
  618.         std::swap(__end_of_storage, x.__end_of_storage);
  619. #else
  620.         ::swap(__start, x.__start);
  621.         ::swap(__finish, x.__finish);
  622.         ::swap(__end_of_storage, x.__end_of_storage);
  623. #endif // _RWSTD_NO_NAMESPACE
  624.       }
  625.       else
  626.       {
  627.         vector<T,Allocator> _x = *this;
  628.         *this = x;
  629.         x=_x;
  630.       } 
  631.     }
  632.  
  633.     void clear()
  634.     {
  635.       erase(begin(),end());
  636.     }
  637.  
  638. #ifndef _RWSTD_STRICT_ANSI
  639.     // Non-standard function for setting buffer allocation size
  640.     size_type allocation_size() { return __buffer_size; }
  641.     size_type allocation_size(size_type new_size) 
  642.     { 
  643.       size_type tmp = __buffer_size; 
  644.       __buffer_size = max((size_type)1,new_size);
  645.       return tmp;
  646.     }
  647. #endif  // _RWSTD_STRICT_ANSI
  648.   };
  649.  
  650.   template <class T, class Allocator>
  651.   inline bool operator== (const vector<T,Allocator>& x, const vector<T,Allocator>& y)
  652.   {
  653.     return x.size() == y.size() && equal(x.begin(), x.end(), y.begin());
  654.   }
  655.  
  656.   template <class T, class Allocator>
  657.   inline bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y)
  658.   {
  659.     return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end());
  660.   }
  661.  
  662. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  663.   template <class T, class Allocator>
  664.   inline bool operator!= (const vector<T,Allocator>& x, const vector<T,Allocator>& y)
  665.   {
  666.     return !(x == y);
  667.   }
  668.  
  669.   template <class T, class Allocator>
  670.   inline bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y)
  671.   {
  672.     return y < x;
  673.   }
  674.  
  675.   template <class T, class Allocator>
  676.   inline bool operator>= (const vector<T,Allocator>& x, const vector<T,Allocator>& y)
  677.   {
  678.     return !(x < y);
  679.   }
  680.  
  681.   template <class T, class Allocator>
  682.   inline bool operator<= (const vector<T,Allocator>& x, const vector<T,Allocator>& y)
  683.   {
  684.     return !(y <  x);
  685.   }
  686.  
  687.   template <class T, class Allocator>
  688.   inline void swap(vector<T,Allocator>& a, vector<T,Allocator>& b)
  689.   {
  690.     a.swap(b);
  691.   }
  692. #endif // !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  693.  
  694. //
  695. // If bool is a builtin type, we provide a vector<bool,allocator> specialization.
  696. // We do not provide the allocator interface for this specialization.
  697. //
  698. #ifndef _RWSTD_NO_BOOL
  699.  
  700. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  701.  
  702.   template <class Allocator>
  703.   class _RWSTDExport vector<bool, Allocator >
  704.   {
  705.  
  706. #else
  707.  
  708. // Use a macro to mutate Allocator into allocator<bool>
  709. #define Allocator allocator<bool>
  710.  
  711.   _RWSTD_TEMPLATE
  712.   class _RWSTDExport vector<bool, allocator<bool> >
  713.   {
  714.  
  715. #endif // _RWSTD_NO_CLASS_PARTIAL_SPEC
  716.  
  717.   public:  
  718.     //
  719.     // types
  720.     //
  721.     typedef Allocator                                 allocator_type;
  722.     typedef bool                                      value_type;
  723.  
  724.   private:
  725. #ifdef _RWSTD_ALLOCATOR
  726. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  727.     typedef _TYPENAME allocator_type::template rebind<unsigned int>::other __value_alloc_type;
  728. #else
  729.     typedef allocator_type::template rebind<unsigned int>::other __value_alloc_type;
  730. #endif
  731. #else
  732.     typedef allocator_interface<allocator_type,unsigned int> __value_alloc_type;
  733. #endif
  734.  
  735.   public:
  736. #ifdef _RWSTD_NO_EMBEDDED_TYPEDEF
  737.     typedef allocator<bool>::size_type               size_type;
  738.     typedef allocator<bool>::difference_type         difference_type;
  739. #else
  740.     typedef _TYPENAME allocator_type::size_type          size_type;
  741.     typedef _TYPENAME allocator_type::difference_type    difference_type;
  742. #endif
  743.  
  744.   protected:
  745.     typedef _TYPENAME __value_alloc_type::pointer       pointer;
  746.     typedef _TYPENAME __value_alloc_type::const_pointer const_pointer;
  747.  
  748.   public:
  749.  
  750.     //
  751.     // forward declarations
  752.     //
  753.     class iterator;
  754.     class const_iterator;
  755.  
  756.     //
  757.     // bit reference
  758.     //
  759.     class reference
  760.     {
  761.       friend class iterator;
  762.       friend class const_iterator;
  763.     protected:
  764.       unsigned int* p;
  765.       unsigned int mask;
  766.       reference (unsigned int* x, unsigned int y) : p(x), mask(y) {}
  767.     public:
  768.       reference () : p(0), mask(0) {}
  769.       operator bool () const { return !(!(*p & mask)); }
  770.       reference& operator= (bool x)
  771.       {
  772.         if (x)      
  773.           *p |= mask;
  774.         else
  775.           *p &= ~mask;
  776.         return *this;
  777.       }
  778.       reference& operator= (const reference& x) { return *this = bool(x); }
  779.  
  780. #ifndef _RWSTD_STRICT_ANSI
  781.       bool operator== (const reference& x) const
  782.       {
  783.         return bool(*this) == bool(x);
  784.       }
  785.       bool operator< (const reference& x) const
  786.       {
  787. #if !defined(_MSC_VER) || defined(__BORLANDC__)
  788.         return bool(*this) < bool(x);
  789. #else
  790.         return int(*this) < int(x);
  791. #endif
  792.       }
  793.       bool operator!= (const reference& x) const
  794.       {
  795.         return !(*this == x);
  796.       }
  797.       bool operator> (const reference& x) const
  798.       {
  799.         return  x < *this;
  800.       }
  801.       bool operator>= (const reference& x) const
  802.       {
  803.         return !(*this < x);
  804.       }
  805.       bool operator<= (const reference& x) const
  806.       {
  807.         return !(*this > x);
  808.       }
  809. #endif // _RWSTD_STRICT_ANSI
  810.  
  811.       void flip () { *p ^= mask; }
  812.     };
  813.     
  814.     typedef bool const_reference;
  815.     //
  816.     // Definition of our iterator.
  817.     //
  818.     class iterator : public _RW_STD::iterator<random_access_iterator_tag,
  819.                                      value_type, difference_type,
  820.                                      pointer,reference>
  821.     {
  822. #if !defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
  823.       friend class vector<bool,Allocator>;
  824. #else
  825.       friend class vector<bool,allocator<bool> >;
  826. #endif
  827.       friend class const_iterator;
  828.  
  829.     protected:
  830.  
  831.       unsigned int* p;
  832.       unsigned int  offset;
  833.  
  834.       void __bump_up ()
  835.       {
  836.         if (offset++ == _RWSTD_WORD_BIT - 1)
  837.         {
  838.           offset = 0; ++p;
  839.         }
  840.       }
  841.       void __bump_down ()
  842.       {
  843.         if (offset-- == 0)
  844.         {
  845.           offset = _RWSTD_WORD_BIT - 1; --p;
  846.         }
  847.       }
  848.  
  849.     public:
  850.       iterator () : p(0), offset(0) {}
  851.       iterator (unsigned int* x, unsigned int y) : p(x), offset(y) {}
  852.  
  853.       reference operator* () const { return reference(p, 1U << offset); }
  854.       iterator& operator++ ()
  855.       {
  856.         __bump_up(); return *this;
  857.       }
  858.       iterator operator++ (int)
  859.       {
  860.         iterator tmp = *this; __bump_up(); return tmp;
  861.       }
  862.       iterator& operator-- ()
  863.       {
  864.         __bump_down(); return *this;
  865.       }
  866.       iterator operator-- (int)
  867.       {
  868.         iterator tmp = *this; __bump_down(); return tmp;
  869.       }
  870.       iterator& operator+= (difference_type i)
  871.       {
  872.         difference_type n = i + offset;
  873.         p += n / _RWSTD_WORD_BIT;
  874.         n = n % _RWSTD_WORD_BIT;
  875.         if (n < 0)
  876.         {
  877.           offset = n + _RWSTD_WORD_BIT; --p;
  878.         }
  879.         else
  880.           offset = n;
  881.         return *this;
  882.       }
  883.       iterator& operator-= (difference_type i)
  884.       {
  885.         *this += -i; return *this;
  886.       }
  887.       iterator operator+ (difference_type i) const
  888.       {
  889.         iterator tmp = *this; return tmp += i;
  890.       }
  891.       iterator operator- (difference_type i) const
  892.       {
  893.         iterator tmp = *this; return tmp -= i;
  894.       }
  895.       difference_type operator- (iterator x) const
  896.       {
  897.         return _RWSTD_WORD_BIT * (p - x.p) + offset - x.offset;
  898.       }
  899.       reference operator[] (difference_type i)
  900.       {
  901.         return *(*this + i);
  902.       }
  903.       bool operator== (const iterator& x) const
  904.       {
  905.         return p == x.p && offset == x.offset;
  906.       }
  907.       bool operator< (const iterator& x) const
  908.       {
  909.         return p < x.p || (p == x.p && offset < x.offset);
  910.       }
  911.       bool operator!= (const iterator& x) const
  912.       {
  913.         return !(*this == x);
  914.       }
  915.       bool operator> (const iterator& x) const
  916.       {
  917.         return x < *this;
  918.       }
  919.       bool operator>= (const iterator& x) const
  920.       {
  921.         return !(*this < x);
  922.       }
  923.       bool operator<= (const iterator& x) const
  924.       {
  925.         return !(*this > x);
  926.       }
  927.     };
  928.     //
  929.     // Definition of our const_iterator.
  930.     //
  931.     class const_iterator
  932.       : public _RW_STD::iterator<random_access_iterator_tag,
  933.                         value_type, difference_type, 
  934.                         const_pointer, const_reference>
  935.     {
  936. #if !defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
  937.       friend class vector<bool,Allocator>;
  938. #else
  939.       friend class vector<bool,allocator<bool> >;
  940. #endif
  941.  
  942.     protected:
  943.  
  944.       unsigned int* p;
  945.       unsigned int offset;
  946.       void  __bump_up ()
  947.       {
  948.         if (offset++ == _RWSTD_WORD_BIT - 1)
  949.         {
  950.           offset = 0; ++p;
  951.         }
  952.       }
  953.       void __bump_down()
  954.       {
  955.         if (offset-- == 0)
  956.         {
  957.           offset = _RWSTD_WORD_BIT - 1; --p;
  958.         }
  959.       }
  960.  
  961.     public:
  962.       const_iterator () : p(0), offset(0) {}
  963.       const_iterator (unsigned int* x, unsigned int y) : p(x), offset(y) {}
  964. #if !defined(_MSC_VER) // JJP
  965.       const_iterator (const _TYPENAME vector<bool,Allocator>::iterator& x) : p(x.p), offset(x.offset) {}
  966. #else
  967.       const_iterator (const iterator& x) : p(x.p), offset(x.offset) {}
  968. #endif
  969.       const_reference operator* () const
  970.       {
  971. #if !defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
  972.         return vector<bool,Allocator >::reference(p, 1U << offset);
  973. #else
  974.         return vector<bool,allocator<bool> >::reference(p, 1U << offset);
  975. #endif
  976.       }
  977.       const_iterator& operator++ ()
  978.       {
  979.         __bump_up(); return *this;
  980.       }
  981.       const_iterator operator++ (int)
  982.       {
  983.         const_iterator tmp = *this; __bump_up(); return tmp;
  984.       }
  985.       const_iterator& operator-- ()
  986.       {
  987.         __bump_down(); return *this;
  988.       }
  989.       const_iterator operator-- (int)
  990.       {
  991.         const_iterator tmp = *this; __bump_down(); return tmp;
  992.       }
  993.       const_iterator& operator+= (difference_type i)
  994.       {
  995.         difference_type n = i + offset;
  996.         p += n / _RWSTD_WORD_BIT;
  997.         n = n % _RWSTD_WORD_BIT;
  998.         if (n < 0)
  999.         {
  1000.           offset = n + _RWSTD_WORD_BIT; --p;
  1001.         }
  1002.         else
  1003.           offset = n;
  1004.         return *this;
  1005.       }
  1006.       const_iterator& operator-= (difference_type i)
  1007.       {
  1008.         *this += -i; return *this;
  1009.       }
  1010.       const_iterator operator+ (difference_type i) const
  1011.       {
  1012.         const_iterator tmp = *this; return tmp += i;
  1013.       }
  1014.       const_iterator operator- (difference_type i) const
  1015.       {
  1016.         const_iterator tmp = *this; return tmp -= i;
  1017.       }
  1018.       difference_type operator- (const_iterator x) const
  1019.       {
  1020.         return _RWSTD_WORD_BIT * (p - x.p) + offset - x.offset;
  1021.       }
  1022.       const_reference operator[] (difference_type i)
  1023.       { 
  1024.         return *(*this + i); 
  1025.       }
  1026.       bool operator== (const const_iterator& x) const
  1027.       {
  1028.         return p == x.p && offset == x.offset;
  1029.       }
  1030.       bool operator< (const const_iterator& x) const
  1031.       {
  1032.         return p < x.p || (p == x.p && offset < x.offset);
  1033.       }
  1034.       bool operator!= (const const_iterator& x) const
  1035.       {
  1036.         return !(*this == x);
  1037.       }
  1038.       bool operator> (const const_iterator& x) const
  1039.       {
  1040.         return x < *this;
  1041.       }
  1042.       bool operator>= (const const_iterator& x) const
  1043.       {
  1044.         return !(*this < x);
  1045.       }
  1046.       bool operator<= (const const_iterator& x) const
  1047.       {
  1048.         return !(*this > x);
  1049.       }
  1050.     };
  1051.     //
  1052.     // types
  1053.     //
  1054. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC 
  1055.     typedef _RW_STD::reverse_iterator<const_iterator> const_reverse_iterator;
  1056.     typedef _RW_STD::reverse_iterator<iterator>  reverse_iterator;
  1057. #else
  1058.     typedef _RW_STD::reverse_iterator<const_iterator, 
  1059.       random_access_iterator_tag, value_type, 
  1060.       const_reference, const_pointer, difference_type>
  1061.       const_reverse_iterator;
  1062.     typedef _RW_STD::reverse_iterator<iterator, 
  1063.       random_access_iterator_tag, value_type,
  1064.       reference, pointer, difference_type>
  1065.       reverse_iterator;
  1066. #endif
  1067.  
  1068.   private:
  1069.     //
  1070.     // These private functions are replicas of generic algorithms.
  1071.     //  We provide them here to avoid putting instantiations of 
  1072.     //  the generic algorithms into an archive or shared library.
  1073.     //  This gives you full flexibilty in deciding where you want
  1074.     //  to put particular instantiations of the generic 
  1075.     //  algorithms.
  1076.     //
  1077.   
  1078.     void __fill (iterator first, iterator last, 
  1079.                const bool& value)
  1080.     {
  1081.       while (first != last) *first++ = value;
  1082.     }
  1083.     void __fill_n (iterator first, size_type n,
  1084.                  const bool& value)
  1085.     {
  1086.       while (n-- > 0) *first++ = value;
  1087.     }
  1088. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1089.     template <class Iterator>
  1090.     iterator __copy (Iterator first, Iterator last,
  1091.                    iterator result)
  1092.     {
  1093.       while (first != last) *result++ = *first++;
  1094.       return result;
  1095.     }
  1096.     template <class Iterator>
  1097.     iterator __copy_backward (Iterator first, Iterator last,
  1098.                             iterator result)
  1099.     {
  1100.       while (first != last) *--result = *--last;
  1101.       return result;
  1102.     }
  1103. #else
  1104.     iterator __copy (const_iterator first, const_iterator last,
  1105.                    iterator result)
  1106.     {
  1107.       while (first != last) *result++ = *first++;
  1108.       return result;
  1109.     }
  1110.     iterator __copy (const bool* first, const bool* last,
  1111.                    iterator result)
  1112.     {
  1113.       while (first != last) *result++ = *first++;
  1114.       return result;
  1115.     }
  1116.     iterator __copy_backward (const_iterator first, const_iterator last,
  1117.                             iterator result)
  1118.     {
  1119.       while (first != last) *--result = *--last;
  1120.       return result;
  1121.     }
  1122.     iterator __copy_backward (const bool* first, const bool* last,
  1123.                             iterator result)
  1124.     {
  1125.       while (first != last) *--result = *--last;
  1126.       return result;
  1127.     }
  1128. #endif
  1129.  
  1130.   protected:
  1131.  
  1132.     iterator                __start;
  1133.     iterator                __finish;
  1134.     __RWSTD::__rw_basis<unsigned int*,allocator_type>   __end_of_storage;
  1135.  
  1136.     unsigned int* __bit_alloc (size_type n)
  1137.     {
  1138.       return __value_alloc_type(__end_of_storage).allocate((n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT,__start.p);
  1139.     }
  1140.     void __init (size_type n)
  1141.     {
  1142.       unsigned int* q = __bit_alloc(n);
  1143.       __end_of_storage = q + (n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
  1144.       __start = iterator(q, 0);
  1145.       __finish = __start + n;
  1146.     }
  1147.     void __insert_aux (iterator position, bool x);
  1148.  
  1149.   public:
  1150.  
  1151.     //
  1152.     // construct/copy/destroy
  1153.     //
  1154. #ifndef _HPACC_
  1155.     vector<bool,Allocator> (const Allocator&  alloc _RWSTD_DEFAULT_ARG(Allocator()))
  1156. #else
  1157.     vector<bool,Allocator> (const Allocator&  alloc)
  1158. #endif
  1159.       : __start(iterator()), __finish(iterator()), 
  1160.         __end_of_storage(0,alloc)
  1161.     { ; }
  1162. #ifndef _HPACC_
  1163.     _EXPLICIT vector<bool,Allocator> (size_type n, bool value = bool(), 
  1164.        const Allocator&  alloc _RWSTD_DEFAULT_ARG(Allocator()))
  1165. #else
  1166.     vector<bool,Allocator> (size_type n, bool value, const Allocator&  alloc)
  1167. #endif
  1168.       : __end_of_storage(0,alloc)
  1169.     {
  1170.       __init(n); 
  1171.       unsigned int * first = __start.p;
  1172.       size_type m = (n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
  1173.       while (m-- > 0) *first++ = value ? ~0 : 0;
  1174.     }
  1175.  
  1176.     vector<bool,Allocator> (const vector<bool,Allocator >& x)
  1177.       : __end_of_storage(0,x.get_allocator())
  1178.     {
  1179.       __init(x.size()); 
  1180.       __copy(x.begin(), x.end(), __start);
  1181.     }
  1182.  
  1183. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1184.     template<class InputIterator>
  1185.     vector<bool,Allocator>  (InputIterator first, InputIterator last)
  1186.       : __end_of_storage(0,Allocator())
  1187.     {
  1188.       size_type n;
  1189.       __initialize(n, size_type(0));
  1190.       distance(first, last, n);
  1191.       __init(n);
  1192.       __copy(first, last, __start);
  1193.     }
  1194. #else
  1195.     vector<bool,Allocator> (const_iterator first, const_iterator last)
  1196.       : __end_of_storage(0,Allocator())
  1197.     {
  1198.       size_type n;
  1199.       __initialize(n, size_type(0));
  1200.       distance(first, last, n);
  1201.       __init(n);
  1202.       __copy(first, last, __start);
  1203.     }
  1204.     vector<bool,Allocator> (const bool* first, const bool* last)
  1205.       : __end_of_storage(0,Allocator())
  1206.     {
  1207.       size_type n;
  1208.       __initialize(n, size_type(0));
  1209.       distance(first, last, n);
  1210.       __init(n);
  1211.       __copy(first, last, __start);
  1212.     }
  1213. #endif
  1214.     ~vector<bool,Allocator> () {
  1215.       __value_alloc_type(__end_of_storage).deallocate(__start.p,  
  1216.         __end_of_storage.data()-__start.p); 
  1217.     }
  1218.     vector<bool,Allocator>& operator= (const vector<bool, Allocator>& x)
  1219.     {
  1220.       if (&x == this) return *this;
  1221.       if (x.size() > capacity())
  1222.       {
  1223.         __value_alloc_type(__end_of_storage).deallocate(__start.p,
  1224.           __end_of_storage.data()-__start.p); 
  1225.         __init(x.size());
  1226.       }
  1227.       __copy(x.begin(), x.end(), begin());
  1228.       __finish = begin() + x.size();
  1229.       return *this;
  1230.     }
  1231. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1232.     template<class InputIterator>
  1233.     void assign (InputIterator first, InputIterator last)
  1234.     { erase(begin(), end()); insert(begin(), first, last); }
  1235. #else
  1236.     void assign (const_iterator first, const_iterator last)
  1237.     { erase(begin(), end()); insert(begin(), first, last); }
  1238. #endif
  1239.  
  1240.     void assign (size_type n, const bool& t = bool())
  1241.     { erase(begin(), end()); insert(begin(), n, t);  }
  1242.  
  1243.     allocator_type get_allocator() const
  1244.     {
  1245.       return (allocator_type)__end_of_storage;
  1246.     }
  1247.  
  1248.     //
  1249.     // iterators
  1250.     //
  1251.     iterator       begin ()       { return __start; }
  1252.     const_iterator begin () const 
  1253.     { return const_iterator(__start.p,__start.offset); }
  1254.     iterator       end   ()       { return __finish; }
  1255.     const_iterator end   () const 
  1256.     { return const_iterator(__finish.p,__finish.offset); }
  1257.  
  1258.     reverse_iterator       rbegin () { return reverse_iterator(end()); }
  1259.     const_reverse_iterator rbegin () const
  1260.     { 
  1261.       return const_reverse_iterator(end()); 
  1262.     }
  1263.     reverse_iterator       rend () { return reverse_iterator(begin()); }
  1264.     const_reverse_iterator rend () const
  1265.     { 
  1266.       return const_reverse_iterator(begin()); 
  1267.     }
  1268.  
  1269.     //
  1270.     // capacity
  1271.     //
  1272.     size_type size     () const { return size_type(end() - begin());  }
  1273.     size_type max_size () const { return __value_alloc_type(__end_of_storage).max_size(); }
  1274.     void resize (size_type new_size, bool c = false);
  1275.     size_type capacity () const
  1276.     {
  1277.       return size_type(const_iterator(__end_of_storage.data(), 0) - begin());
  1278.     }
  1279.     bool empty () const { return begin() == end(); }
  1280.     void reserve (size_type n)
  1281.     {
  1282.       _RWSTD_THROW(n > max_size(), length_error,
  1283.         __RWSTD::except_msg_string(__RWSTD::__rwse_InvalidSizeParam,
  1284.           "vector<bool>::reserve(size_t)",n,max_size()).msgstr());
  1285.       if (capacity() < n)
  1286.       {
  1287.         unsigned int* q = __bit_alloc(n);
  1288.         __finish = __copy(begin(), end(), iterator(q, 0));
  1289.         __value_alloc_type(__end_of_storage).deallocate(__start.p,
  1290.                                                    __end_of_storage.data()-__start.p);
  1291.         __start = iterator(q, 0);
  1292.         __end_of_storage = q + (n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
  1293.       }
  1294.     }
  1295.  
  1296.     //
  1297.     // element access
  1298.     //
  1299.     reference       operator[] (size_type n)       
  1300.     { 
  1301. #ifdef _RWSTD_BOUNDS_CHECKING
  1302.       _RWSTD_THROW(n >= size(), out_of_range,
  1303.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  1304.           "vector<bool>::[](size_t)",n,size()).msgstr());
  1305. #endif
  1306.       return *(begin() + n); 
  1307.     }
  1308.     const_reference operator[] (size_type n) const 
  1309.     { 
  1310. #ifdef _RWSTD_BOUNDS_CHECKING
  1311.       _RWSTD_THROW(n >= size(), out_of_range,
  1312.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  1313.           "vector<bool>::[](size_t)",n,size()).msgstr());
  1314. #endif
  1315.       return *(begin() + n); 
  1316.     }
  1317.     reference       at (size_type n)               
  1318.     { 
  1319.       _RWSTD_THROW(n >= size(), out_of_range,
  1320.         __RWSTD::except_msg_string(__RWSTD::rwse_OutOfRange,
  1321.           "vector<bool>:: at(size_t)",n,size()).msgstr());
  1322.       return *(begin() + n); 
  1323.     }
  1324.     const_reference at (size_type n)   const 
  1325.     {
  1326.       _RWSTD_THROW(n >= size(), out_of_range,
  1327.         __RWSTD::except_msg_string( __RWSTD::rwse_OutOfRange,
  1328.           "vector<bool>:: at(size_t) const",n,size()).msgstr());
  1329.  
  1330.       return *(begin() + n); 
  1331.     }
  1332.     reference       front ()       { return *begin();     }
  1333.     const_reference front () const { return *begin();     }
  1334.     reference       back  ()       { return *(end() - 1); }
  1335.     const_reference back  () const { return *(end() - 1); }
  1336.     
  1337.     //
  1338.     // modifiers
  1339.     //
  1340.     void push_back (const bool& x)
  1341.     {
  1342.       if (__finish.p != __end_of_storage.data())
  1343.         *__finish++ = x;
  1344.       else
  1345.         __insert_aux(end(), x);
  1346.     }
  1347.     void pop_back () { --__finish; }
  1348.  
  1349.     iterator insert (iterator position, const bool& x = bool())
  1350.     {
  1351.       size_type n = position - begin();
  1352.       if (__finish.p != __end_of_storage.data() && position == end())
  1353.         *__finish++ = x;
  1354.       else
  1355.         __insert_aux(position, x);
  1356.       return begin() + n;
  1357.     }
  1358.     void insert (iterator position, size_type n, const bool& x);
  1359.  
  1360. #ifndef _RWSTD_NO_MEMBER_TEMPLATES
  1361.     template<class InputIterator>
  1362.     void insert (iterator position, InputIterator first, InputIterator last);
  1363. #else
  1364.     void insert (iterator position, const_iterator first, 
  1365.                  const_iterator last);
  1366. #endif
  1367.  
  1368.     iterator erase (iterator position)
  1369.     {
  1370.       if (!(position + 1 == end()))
  1371.         __copy(position + 1, end(), position);
  1372.       --__finish;
  1373.       return position;
  1374.     }
  1375.     iterator erase(iterator first, iterator last)
  1376.     {
  1377.       __finish = __copy(last, end(), first);
  1378.       return first;
  1379.     }
  1380.     void swap (vector<bool,Allocator >& x)
  1381.     {
  1382.       if((allocator_type)__end_of_storage==(allocator_type)x.__end_of_storage)
  1383.       {
  1384. #ifndef _RWSTD_NO_NAMESPACE
  1385.         std::swap(__start,          x.__start);
  1386.         std::swap(__finish,         x.__finish);
  1387.         std::swap(__end_of_storage, x.__end_of_storage);
  1388. #else
  1389.         ::swap(__start,          x.__start); 
  1390.         ::swap(__finish,         x.__finish);
  1391.         ::swap(__end_of_storage, x.__end_of_storage);
  1392. #endif // _RWSTD_NO_NAMESPACE
  1393.       }
  1394.       else
  1395.       {
  1396.         vector<bool,Allocator> _x = *this;
  1397.         *this = x;
  1398.         x=_x;
  1399.       } 
  1400.     }
  1401.     static void swap(reference x, reference y);
  1402.     void flip ();
  1403.     void clear()
  1404.     {
  1405.       erase(begin(),end());
  1406.     }
  1407.   };
  1408.  
  1409. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1410.   template <class Allocator>
  1411. #endif
  1412.   inline bool operator== (const vector<bool,Allocator >& x, 
  1413.                           const vector<bool,Allocator >& y)
  1414.   {
  1415.     if (x.size() == y.size())
  1416.     {
  1417.       _TYPENAME vector<bool,Allocator >::const_iterator first1 = x.begin(), 
  1418.       last1 =x.end(),
  1419.       first2 = y.begin();
  1420.             
  1421.       while (first1 != last1 && *first1 == *first2)
  1422.       {
  1423.         ++first1;
  1424.         ++first2;
  1425.       }
  1426.       return first1 == last1;
  1427.     }
  1428.     return false;
  1429.   }
  1430.  
  1431. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1432.   template <class Allocator>
  1433. #endif
  1434.   inline bool operator< (const vector<bool,Allocator >& x, 
  1435.                          const vector<bool,Allocator >& y)
  1436.   {
  1437.     _TYPENAME vector<bool,Allocator >::const_iterator first1 = x.begin(), 
  1438.     last1 =x.end(),
  1439.     first2 = y.begin(),
  1440.     last2 = y.end();
  1441.  
  1442.     while (first1 != last1 && first2 != last2)
  1443.     {
  1444.       if ((int)*first1 < (int)*first2)     return true;
  1445.       if ((int)*first2++ < (int)*first1++) return false;
  1446.     }
  1447.     return first1 == last1 && first2 != last2;
  1448.   }
  1449.  
  1450. #if !defined(_RWSTD_NO_NAMESPACE) || !defined(_RWSTD_NO_PART_SPEC_OVERLOAD)
  1451. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1452.   template <class Allocator>
  1453. #endif
  1454.   inline bool operator!= (const vector<bool,Allocator >& x, 
  1455.                           const vector<bool,Allocator >& y)
  1456.   {
  1457.     return !(x == y);
  1458.   }
  1459.  
  1460. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1461.   template <class Allocator>
  1462. #endif
  1463.   inline bool operator> (const vector<bool,Allocator >& x, 
  1464.                          const vector<bool,Allocator >& y)
  1465.   {
  1466.     return y < x;
  1467.   }
  1468.  
  1469. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1470.   template <class Allocator>
  1471. #endif
  1472.   inline bool operator>= (const vector<bool,Allocator >& x, 
  1473.                           const vector<bool,Allocator >& y)
  1474.   {
  1475.     return !(x < y);
  1476.   }
  1477.  
  1478. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1479.   template <class Allocator>
  1480. #endif
  1481.   inline bool operator<= (const vector<bool,Allocator >& x, 
  1482.                           const vector<bool,Allocator >& y)
  1483.   {
  1484.     return !(y <  x);
  1485.   }
  1486.  
  1487. #ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1488.   template <class Allocator>
  1489. #endif
  1490.   inline void swap(vector<bool,Allocator >& a, vector<bool,Allocator >& b)
  1491.   {
  1492.     a.swap(b);
  1493.   }
  1494.  
  1495. #endif
  1496.  
  1497. #ifdef _RWSTD_NO_CLASS_PARTIAL_SPEC
  1498. #undef Allocator 
  1499. #endif
  1500.  
  1501. #endif /*_RWSTD_NO_BOOL*/
  1502.  
  1503. #ifndef _RWSTD_NO_NAMESPACE
  1504. }
  1505. #endif
  1506.  
  1507. #if defined (_RWSTD_NO_TEMPLATE_REPOSITORY)
  1508. #include <vector.cc>
  1509. #endif
  1510.  
  1511. #undef vector
  1512.  
  1513. #ifndef __USING_STD_NAMES__
  1514.   using namespace std;
  1515. #endif
  1516.  
  1517. #endif /*__STD_VECTOR__*/
  1518. #pragma option pop
  1519. #endif /* __VECTOR_H */
  1520.