epoc32/include/stdapis/stlportv5/stl/_bvector.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/stlport/stl/_bvector.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
     1 /*
     2  *
     3  * Copyright (c) 1994
     4  * Hewlett-Packard Company
     5  *
     6  * Copyright (c) 1996,1997
     7  * Silicon Graphics Computer Systems, Inc.
     8  *
     9  * Copyright (c) 1997
    10  * Moscow Center for SPARC Technology
    11  *
    12  * Copyright (c) 1999 
    13  * Boris Fomitchev
    14  *
    15  * This material is provided "as is", with absolutely no warranty expressed
    16  * or implied. Any use is at your own risk.
    17  *
    18  * Permission to use or copy this software for any purpose is hereby granted 
    19  * without fee, provided the above notices are retained on all copies.
    20  * Permission to modify the code and to distribute modified code is granted,
    21  * provided the above notices are retained, and a notice that the code was
    22  * modified is included with the above copyright notice.
    23  *
    24  */
    25 
    26 /* NOTE: This is an internal header file, included by other STL headers.
    27  *   You should not attempt to use it directly.
    28  */
    29 
    30 #ifndef _STLP_INTERNAL_BVECTOR_H
    31 #define _STLP_INTERNAL_BVECTOR_H
    32 
    33 #ifndef _STLP_INTERNAL_VECTOR_H
    34 # include <stl/_vector.h>
    35 # endif
    36 
    37 #ifndef __WORD_BIT
    38 #define __WORD_BIT (int(CHAR_BIT*sizeof(unsigned int)))
    39 #endif
    40 
    41 _STLP_BEGIN_NAMESPACE 
    42 
    43 struct _Bit_reference {
    44   unsigned int* _M_p;
    45   unsigned int _M_mask;
    46   _Bit_reference(unsigned int* __x, unsigned int __y) 
    47     : _M_p(__x), _M_mask(__y) {}
    48 
    49 public:
    50   _Bit_reference() : _M_p(0), _M_mask(0) {}
    51 
    52   operator bool() const { 
    53 	  return !(!(*_M_p & _M_mask)); 
    54   }
    55   _Bit_reference& operator=(bool __x) {
    56     if (__x)  *_M_p |= _M_mask;
    57     else      *_M_p &= ~_M_mask;
    58     return *this;
    59   }
    60   _Bit_reference& operator=(const _Bit_reference& __x) {
    61 	  return *this = bool(__x); 
    62   }
    63   bool operator==(const _Bit_reference& __x) const {
    64 	  return bool(*this) == bool(__x); 
    65   }
    66   bool operator<(const _Bit_reference& __x) const {
    67     return !bool(*this) && bool(__x);
    68   }
    69 
    70   _Bit_reference& operator |= (bool __x) {
    71 	  if (__x)
    72 		  *_M_p |= _M_mask;
    73 	  return *this;
    74   }
    75   _Bit_reference& operator &= (bool __x) {
    76 	  if (!__x)
    77 		  *_M_p &= ~_M_mask;
    78 	  return *this;
    79   }
    80   void flip() { *_M_p ^= _M_mask; }
    81 };
    82 
    83 
    84 inline void swap(_Bit_reference& __x, _Bit_reference& __y)
    85 {
    86   bool __tmp = (bool)__x;
    87   __x = __y;
    88   __y = __tmp;
    89 }
    90 
    91 struct _Bit_iterator_base;
    92 
    93 struct _Bit_iterator_base
    94 {
    95   typedef ptrdiff_t difference_type;
    96 
    97   unsigned int* _M_p;
    98   unsigned int  _M_offset;
    99 
   100   void _M_bump_up() {
   101     if (_M_offset++ == __WORD_BIT - 1) {
   102       _M_offset = 0;
   103       ++_M_p;
   104     }
   105   }
   106 
   107   void _M_bump_down() {
   108     if (_M_offset-- == 0) {
   109       _M_offset = __WORD_BIT - 1;
   110       --_M_p;
   111     }
   112   }
   113 
   114   _Bit_iterator_base() : _M_p(0), _M_offset(0) {}
   115   _Bit_iterator_base(unsigned int* __x, unsigned int __y) : _M_p(__x), _M_offset(__y) {}
   116   //  _Bit_iterator_base( const _Bit_iterator_base& __x) : _M_p(__x._M_p), _M_offset(__x._M_offset) {}
   117   //  _Bit_iterator_base& operator = ( const _Bit_iterator_base& __x) { _M_p = __x._M_p ; _M_offset = __x._M_offset ; return *this; }
   118 
   119   void _M_advance (difference_type __i) {
   120     difference_type __n = __i + _M_offset;
   121     _M_p += __n / __WORD_BIT;
   122     __n = __n % __WORD_BIT;
   123     if (__n < 0) {
   124       _M_offset = (unsigned int) __n + __WORD_BIT;
   125       --_M_p;
   126     } else
   127       _M_offset = (unsigned int) __n;
   128   }
   129 
   130   difference_type _M_subtract(const _Bit_iterator_base& __x) const {
   131     return __WORD_BIT * (_M_p - __x._M_p) + _M_offset - __x._M_offset;
   132   }
   133 };
   134 
   135 inline bool  _STLP_CALL operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
   136   return __y._M_p == __x._M_p && __y._M_offset == __x._M_offset;
   137 }
   138 inline bool  _STLP_CALL operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
   139   return __y._M_p != __x._M_p || __y._M_offset != __x._M_offset;
   140 }
   141 
   142 inline bool _STLP_CALL operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
   143   return __x._M_p < __y._M_p || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset);
   144 }
   145 
   146 inline bool _STLP_CALL operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)  { 
   147   return operator <(__y , __x); 
   148 }
   149 inline bool _STLP_CALL operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 
   150   return !(__y < __x); 
   151 }
   152 inline bool _STLP_CALL operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 
   153   return !(__x < __y); 
   154 }
   155 
   156 template <class _Ref, class _Ptr>
   157 struct _Bit_iter : public _Bit_iterator_base
   158 {
   159   typedef _Ref  reference;
   160   typedef _Ptr  pointer;
   161   typedef _Bit_iter<_Ref, _Ptr> _Self;
   162   typedef random_access_iterator_tag iterator_category;
   163   typedef bool value_type;
   164   typedef ptrdiff_t difference_type;
   165   typedef size_t size_type;
   166 
   167   _Bit_iter(unsigned int* __x, unsigned int __y) : _Bit_iterator_base(__x, __y) {}
   168   _Bit_iter() {}
   169 
   170   _Bit_iter(const _Bit_iter<_Bit_reference, _Bit_reference*>& __x): 
   171     _Bit_iterator_base((const _Bit_iterator_base&)__x) {}
   172 
   173   //  _Self& operator = (const _Bit_iter<_Bit_reference, _Bit_reference*>& __x)
   174   //   { (_Bit_iterator_base&)*this = (const _Bit_iterator_base&)__x; return *this; }
   175 
   176   reference operator*() const { 
   177     return _Bit_reference(_M_p, 1UL << _M_offset); 
   178   }
   179   _Self& operator++() {
   180     _M_bump_up();
   181     return *this;
   182   }
   183   _Self operator++(int) {
   184     _Self __tmp = *this;
   185     _M_bump_up();
   186     return __tmp;
   187   }
   188   _Self& operator--() {
   189     _M_bump_down();
   190     return *this;
   191   }
   192   _Self operator--(int) {
   193     _Self __tmp = *this;
   194     _M_bump_down();
   195     return __tmp;
   196   }
   197   _Self& operator+=(difference_type __i) {
   198     _M_advance(__i);
   199     return *this;
   200   }
   201   _Self& operator-=(difference_type __i) {
   202     *this += -__i;
   203     return *this;
   204   }
   205   _Self operator+(difference_type __i) const {
   206     _Self __tmp = *this;
   207     return __tmp += __i;
   208   }
   209   _Self operator-(difference_type __i) const {
   210     _Self __tmp = *this;
   211     return __tmp -= __i;
   212   }
   213   difference_type operator-(const _Self& __x) const {
   214     return _M_subtract(__x);
   215   }
   216   reference operator[](difference_type __i) { return *(*this + __i); }
   217 };
   218 
   219 template <class _Ref, class _Ptr>
   220 inline _Bit_iter<_Ref,_Ptr>  _STLP_CALL
   221 operator+(ptrdiff_t __n, const _Bit_iter<_Ref, _Ptr>& __x) {
   222    return __x + __n;
   223 }
   224 
   225 # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   226 inline random_access_iterator_tag  iterator_category(const _Bit_iterator_base&) {return random_access_iterator_tag();}
   227 inline ptrdiff_t* distance_type(const _Bit_iterator_base&) {return (ptrdiff_t*)0;}
   228 inline bool* value_type(const _Bit_iter<_Bit_reference, _Bit_reference*>&) {return (bool*)0;}
   229 inline bool* value_type(const _Bit_iter<bool, const bool*>&) {return (bool*)0;}
   230 # endif
   231 
   232 typedef _Bit_iter<bool, const bool*> _Bit_const_iterator;
   233 typedef _Bit_iter<_Bit_reference, _Bit_reference*> _Bit_iterator;
   234 
   235 // Bit-vector base class, which encapsulates the difference between
   236 //  old SGI-style allocators and standard-conforming allocators.
   237 
   238 
   239 template <class _Alloc>
   240 class _Bvector_base
   241 {
   242 public:
   243   _STLP_FORCE_ALLOCATORS(bool, _Alloc)
   244   typedef typename _Alloc_traits<bool, _Alloc>::allocator_type allocator_type;
   245   typedef unsigned int __chunk_type;
   246   typedef typename _Alloc_traits<__chunk_type, 
   247           _Alloc>::allocator_type __chunk_allocator_type;
   248   allocator_type get_allocator() const { 
   249     return _STLP_CONVERT_ALLOCATOR((const __chunk_allocator_type&)_M_end_of_storage, bool); 
   250   }
   251   static allocator_type __get_dfl_allocator() { return allocator_type(); }
   252    
   253   _Bvector_base(const allocator_type& __a)
   254     : _M_start(), _M_finish(), _M_end_of_storage(_STLP_CONVERT_ALLOCATOR(__a, __chunk_type),
   255 						 (__chunk_type*)0) {
   256   }
   257   ~_Bvector_base() { _M_deallocate();
   258   }
   259 
   260 protected:
   261 
   262   unsigned int* _M_bit_alloc(size_t __n) 
   263     { return _M_end_of_storage.allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
   264   void _M_deallocate() {
   265     if (_M_start._M_p)
   266       _M_end_of_storage.deallocate(_M_start._M_p,
   267 				   _M_end_of_storage._M_data - _M_start._M_p);
   268   }
   269 
   270   _Bit_iterator _M_start;
   271   _Bit_iterator _M_finish;
   272   _STLP_alloc_proxy<__chunk_type*, __chunk_type, __chunk_allocator_type> _M_end_of_storage;  
   273 };
   274 
   275 
   276 // The next few lines are confusing.  What we're doing is declaring a
   277 //  partial specialization of vector<T, Alloc> if we have the necessary
   278 //  compiler support.  Otherwise, we define a class bit_vector which uses
   279 //  the default allocator. 
   280 
   281 #if defined(_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined(_STLP_NO_BOOL) && ! defined (__SUNPRO_CC)
   282 # define _STLP_VECBOOL_TEMPLATE
   283 # define __BVEC_TMPL_HEADER template <class _Alloc>
   284 #else
   285 # undef _STLP_VECBOOL_TEMPLATE
   286 # ifdef _STLP_NO_BOOL
   287 #  define __BVEC_TMPL_HEADER
   288 # else
   289 #  define __BVEC_TMPL_HEADER _STLP_TEMPLATE_NULL
   290 # endif
   291 # if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))			//*TY 12/17/2000 - 
   292 #  define _Alloc _STLP_DEFAULT_ALLOCATOR(bool)
   293 # else
   294 #  define _Alloc allocator<bool>
   295 # endif
   296 #endif
   297 
   298 #ifdef _STLP_NO_BOOL
   299 # define __BVECTOR_QUALIFIED bit_vector
   300 # define __BVECTOR           bit_vector
   301 #else
   302 # ifdef _STLP_VECBOOL_TEMPLATE
   303 #  define __BVECTOR_QUALIFIED __WORKAROUND_DBG_RENAME(vector) <bool, _Alloc>
   304 # else
   305 #  define __BVECTOR_QUALIFIED __WORKAROUND_DBG_RENAME(vector) <bool, allocator<bool> >
   306 # endif
   307 #if defined (_STLP_PARTIAL_SPEC_NEEDS_TEMPLATE_ARGS)
   308 # define __BVECTOR __BVECTOR_QUALIFIED
   309 #else
   310 # define __BVECTOR __WORKAROUND_DBG_RENAME(vector)
   311 #endif
   312 #endif
   313 
   314 
   315 __BVEC_TMPL_HEADER
   316 class __BVECTOR_QUALIFIED : public _Bvector_base<_Alloc >
   317 {
   318   typedef _Bvector_base<_Alloc > _Base;
   319   typedef __BVECTOR_QUALIFIED _Self;
   320 public:
   321   typedef bool value_type;
   322   typedef size_t size_type;
   323   typedef ptrdiff_t difference_type; 
   324   typedef _Bit_reference reference;
   325   typedef bool const_reference;
   326   typedef _Bit_reference* pointer;
   327   typedef const bool* const_pointer;
   328   typedef random_access_iterator_tag _Iterator_category;
   329 
   330   typedef _Bit_iterator                iterator;
   331   typedef _Bit_const_iterator          const_iterator;
   332 
   333 #if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
   334   typedef _STLP_STD::reverse_iterator<const_iterator> const_reverse_iterator;
   335   typedef _STLP_STD::reverse_iterator<iterator> reverse_iterator;
   336 #else /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   337 # if defined (_STLP_MSVC50_COMPATIBILITY)
   338   typedef _STLP_STD::reverse_iterator<const_iterator, value_type, const_reference, 
   339   const_pointer, difference_type> const_reverse_iterator;
   340   typedef _STLP_STD::reverse_iterator<iterator, value_type, reference, reference*, 
   341   difference_type> reverse_iterator;
   342 # else
   343   typedef _STLP_STD::reverse_iterator<const_iterator, value_type, const_reference, 
   344                                   difference_type> const_reverse_iterator;
   345   typedef _STLP_STD::reverse_iterator<iterator, value_type, reference, difference_type>
   346           reverse_iterator;
   347 # endif
   348 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   349 
   350 # ifdef _STLP_VECBOOL_TEMPLATE
   351   typedef typename _Bvector_base<_Alloc >::allocator_type allocator_type;
   352   typedef typename _Bvector_base<_Alloc >::__chunk_type __chunk_type ;
   353 # else
   354   typedef _Bvector_base<_Alloc >::allocator_type allocator_type;
   355   typedef _Bvector_base<_Alloc >::__chunk_type __chunk_type ;
   356 # endif
   357 
   358 protected:
   359 
   360   void _M_initialize(size_type __n) {
   361     unsigned int* __q = this->_M_bit_alloc(__n);
   362     this->_M_end_of_storage._M_data = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
   363     this->_M_start = iterator(__q, 0);
   364     this->_M_finish = this->_M_start + difference_type(__n);
   365   }
   366   void _M_insert_aux(iterator __position, bool __x) {
   367     if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
   368       __copy_backward(__position, this->_M_finish, this->_M_finish + 1, random_access_iterator_tag(), (difference_type*)0 );
   369       *__position = __x;
   370       ++this->_M_finish;
   371     }
   372     else {
   373       size_type __len = size() ? 2 * size() : __WORD_BIT;
   374       unsigned int* __q = this->_M_bit_alloc(__len);
   375       iterator __i = copy(begin(), __position, iterator(__q, 0));
   376       *__i++ = __x;
   377       this->_M_finish = copy(__position, end(), __i);
   378       this->_M_deallocate();
   379       this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   380       this->_M_start = iterator(__q, 0);
   381     }
   382   }
   383 
   384 #ifdef _STLP_MEMBER_TEMPLATES
   385   template <class _InputIterator>
   386   void _M_initialize_range(_InputIterator __first, _InputIterator __last,
   387 			const input_iterator_tag &) {
   388     this->_M_start = iterator();
   389     this->_M_finish = iterator();
   390     this->_M_end_of_storage._M_data = 0;
   391     for ( ; __first != __last; ++__first) 
   392       push_back(*__first);
   393   }
   394 
   395   template <class _ForwardIterator>
   396   void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
   397                            const forward_iterator_tag &) {
   398     size_type __n = distance(__first, __last);
   399     _M_initialize(__n);
   400     //    copy(__first, __last, _M_start);
   401     copy(__first, __last, this->_M_start); // dwa 12/22/99 -- resolving ambiguous reference.
   402   }
   403 
   404   template <class _InputIterator>
   405   void _M_insert_range(iterator __pos,
   406                        _InputIterator __first, _InputIterator __last,
   407                        const input_iterator_tag &) {
   408     for ( ; __first != __last; ++__first) {
   409       __pos = insert(__pos, *__first);
   410       ++__pos;
   411     }
   412   }
   413 
   414   template <class _ForwardIterator>
   415   void _M_insert_range(iterator __position,
   416                        _ForwardIterator __first, _ForwardIterator __last,
   417                        const forward_iterator_tag &) {
   418     if (__first != __last) {
   419       size_type __n = distance(__first, __last);
   420       if (capacity() - size() >= __n) {
   421         __copy_backward(__position, end(), this->_M_finish + difference_type(__n), random_access_iterator_tag(), (difference_type*)0 );
   422         copy(__first, __last, __position);
   423         this->_M_finish += difference_type(__n);
   424       }
   425       else {
   426         size_type __len = size() + (max)(size(), __n);
   427         unsigned int* __q = this->_M_bit_alloc(__len);
   428         iterator __i = copy(begin(), __position, iterator(__q, 0));
   429         __i = copy(__first, __last, __i);
   430         this->_M_finish = copy(__position, end(), __i);
   431         this->_M_deallocate();
   432         this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   433         this->_M_start = iterator(__q, 0);
   434       }
   435     }
   436   }      
   437 
   438 #endif /* _STLP_MEMBER_TEMPLATES */
   439 
   440 public:
   441   iterator begin() { return this->_M_start; }
   442   const_iterator begin() const { return this->_M_start; }
   443   iterator end() { return this->_M_finish; }
   444   const_iterator end() const { return this->_M_finish; }
   445 
   446   reverse_iterator rbegin() { return reverse_iterator(end()); }
   447   const_reverse_iterator rbegin() const { 
   448     return const_reverse_iterator(end()); 
   449   }
   450   reverse_iterator rend() { return reverse_iterator(begin()); }
   451   const_reverse_iterator rend() const { 
   452     return const_reverse_iterator(begin()); 
   453   }
   454 
   455   size_type size() const { return size_type(end() - begin()); }
   456   size_type max_size() const { return size_type(-1); }
   457   size_type capacity() const {
   458     return size_type(const_iterator(this->_M_end_of_storage._M_data, 0) - begin());
   459   }
   460   bool empty() const { return begin() == end(); }
   461   reference operator[](size_type __n) 
   462   { return *(begin() + difference_type(__n)); }
   463   const_reference operator[](size_type __n) const 
   464   { return *(begin() + difference_type(__n)); }
   465 
   466   void _M_range_check(size_type __n) const {
   467     if (__n >= this->size())
   468       __stl_throw_range_error("vector<bool>");
   469   }
   470 
   471   reference at(size_type __n)
   472     { _M_range_check(__n); return (*this)[__n]; }
   473   const_reference at(size_type __n) const
   474     { _M_range_check(__n); return (*this)[__n]; }
   475 
   476   explicit __BVECTOR(const allocator_type& __a = allocator_type())
   477     : _Bvector_base<_Alloc >(__a) {
   478     _STLP_POP_IF_CHECK
   479   }
   480 
   481   __BVECTOR(size_type __n, bool __val,
   482             const allocator_type& __a = 
   483 	    allocator_type())
   484     : _Bvector_base<_Alloc >(__a)
   485   {
   486     _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   487     _M_initialize(__n);
   488     fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __val ? ~0 : 0);
   489     _STLP_POP_CLEANUP_ITEM	  
   490   }
   491 
   492   explicit __BVECTOR(size_type __n)
   493     : _Bvector_base<_Alloc >(allocator_type())
   494   {
   495     _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   496     _M_initialize(__n);
   497     fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), 0);
   498     _STLP_POP_CLEANUP_ITEM  
   499   }
   500 
   501   __BVECTOR(const _Self& __x) : _Bvector_base<_Alloc >(__x.get_allocator()) {
   502     _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   503     _M_initialize(__x.size());
   504     copy(__x.begin(), __x.end(), this->_M_start);
   505     _STLP_POP_CLEANUP_ITEM  
   506   }
   507 
   508 #if defined (_STLP_MEMBER_TEMPLATES)
   509   template <class _Integer>
   510   void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
   511     _M_initialize(__n);
   512     fill(this->_M_start._M_p, this->_M_end_of_storage._M_data, __x ? ~0 : 0);
   513   }
   514     
   515   template <class _InputIterator>
   516   void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
   517                               const __false_type&) {
   518     _M_initialize_range(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
   519   }
   520 # ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
   521   // Check whether it's an integral type.  If so, it's not an iterator.
   522   template <class _InputIterator>
   523   __BVECTOR(_InputIterator __first, _InputIterator __last)
   524     : _Base(allocator_type())
   525   {
   526     typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
   527     _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   528     _M_initialize_dispatch(__first, __last, _Integral());
   529     _STLP_POP_CLEANUP_ITEM  
   530   }
   531 # endif
   532   template <class _InputIterator>
   533   __BVECTOR(_InputIterator __first, _InputIterator __last,
   534             const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
   535     : _Base(__a)
   536   {
   537     typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
   538     _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   539     _M_initialize_dispatch(__first, __last, _Integral());
   540     _STLP_POP_CLEANUP_ITEM  
   541   }
   542 #else /* _STLP_MEMBER_TEMPLATES */
   543   __BVECTOR(const_iterator __first, const_iterator __last,
   544             const allocator_type& __a = allocator_type())
   545     : _Bvector_base<_Alloc >(__a)
   546   {
   547     _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   548     size_type __n = distance(__first, __last);
   549     _M_initialize(__n);
   550     copy(__first, __last, this->_M_start);
   551     _STLP_POP_CLEANUP_ITEM  
   552   }
   553   __BVECTOR(const bool* __first, const bool* __last,
   554             const allocator_type& __a = allocator_type())
   555     : _Bvector_base<_Alloc >(__a)
   556   {
   557     size_type __n = distance(__first, __last);
   558     _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   559     _M_initialize(__n);
   560     copy(__first, __last, this->_M_start);
   561     _STLP_POP_CLEANUP_ITEM  
   562   }
   563 #endif /* _STLP_MEMBER_TEMPLATES */
   564 
   565   ~__BVECTOR() { }
   566 
   567   __BVECTOR_QUALIFIED& operator=(const __BVECTOR_QUALIFIED& __x) {
   568     if (&__x == this) return *this;
   569     if (__x.size() > capacity()) {
   570       this->_M_deallocate();
   571       _M_initialize(__x.size());
   572     }
   573     copy(__x.begin(), __x.end(), begin());
   574     this->_M_finish = begin() + difference_type(__x.size());
   575     return *this;
   576   }
   577 
   578 #ifdef _STLP_USE_TRAP_LEAVE
   579 public:
   580   static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
   581   static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
   582 #endif
   583 
   584   // assign(), a generalized assignment member function.  Two
   585   // versions: one that takes a count, and one that takes a range.
   586   // The range version is a member template, so we dispatch on whether
   587   // or not the type is an integer.
   588 
   589   void _M_fill_assign(size_t __n, bool __x) {
   590     if (__n > size()) {
   591       fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
   592       insert(end(), __n - size(), __x);
   593     }
   594     else {
   595       erase(begin() + __n, end());
   596       fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
   597     }
   598   }
   599   void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
   600 
   601 #ifdef _STLP_MEMBER_TEMPLATES
   602 
   603   template <class _InputIterator>
   604   void assign(_InputIterator __first, _InputIterator __last) {
   605     typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
   606     _M_assign_dispatch(__first, __last, _Integral());
   607   }
   608 
   609   template <class _Integer>
   610   void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
   611     { _M_fill_assign((size_t) __n, (bool) __val); }
   612 
   613   template <class _InputIter>
   614   void _M_assign_dispatch(_InputIter __first, _InputIter __last, const __false_type&)
   615     { _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
   616 
   617   template <class _InputIterator>
   618   void _M_assign_aux(_InputIterator __first, _InputIterator __last,
   619                      const input_iterator_tag &) {
   620     iterator __cur = begin();
   621     for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
   622       *__cur = *__first;
   623     if (__first == __last)
   624       erase(__cur, end());
   625     else
   626       insert(end(), __first, __last);
   627   }
   628 
   629   template <class _ForwardIterator>
   630   void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
   631                      const forward_iterator_tag &) {
   632     size_type __len = distance(__first, __last);
   633     if (__len < size())
   634       erase(copy(__first, __last, begin()), end());
   635     else {
   636       _ForwardIterator __mid = __first;
   637       advance(__mid, size());
   638       copy(__first, __mid, begin());
   639       insert(end(), __mid, __last);
   640     }
   641   }    
   642 
   643 #endif /* _STLP_MEMBER_TEMPLATES */
   644 
   645   void reserve(size_type __n) {
   646     if (capacity() < __n) {
   647       unsigned int* __q = this->_M_bit_alloc(__n);
   648       _Bit_iterator __z(__q, 0);
   649       this->_M_finish = copy(begin(), end(), __z);
   650       this->_M_deallocate();
   651       this->_M_start = iterator(__q, 0);
   652       this->_M_end_of_storage._M_data = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
   653     }
   654   }
   655 
   656   reference front() { return *begin(); }
   657   const_reference front() const { return *begin(); }
   658   reference back() { return *(end() - 1); }
   659   const_reference back() const { return *(end() - 1); }
   660   void push_back(bool __x) {
   661     if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
   662       *(this->_M_finish) = __x;
   663       ++this->_M_finish;
   664     }
   665     else
   666       _M_insert_aux(end(), __x);
   667   }
   668   void swap(__BVECTOR_QUALIFIED& __x) {
   669     _STLP_STD::swap(this->_M_start, __x._M_start);
   670     _STLP_STD::swap(this->_M_finish, __x._M_finish);
   671     _STLP_STD::swap(this->_M_end_of_storage, __x._M_end_of_storage);
   672   }
   673   iterator insert(iterator __position, bool __x = bool()) {
   674     difference_type __n = __position - begin();
   675     if (this->_M_finish._M_p != this->_M_end_of_storage._M_data && __position == end()) {
   676       *(this->_M_finish) = __x;
   677       ++this->_M_finish;
   678     }
   679     else
   680       _M_insert_aux(__position, __x);
   681     return begin() + __n;
   682   }
   683 
   684 #if defined ( _STLP_MEMBER_TEMPLATES )
   685 
   686   template <class _Integer>
   687   void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
   688                           const __true_type&) {
   689     _M_fill_insert(__pos, (size_type) __n, (bool) __x);
   690   }
   691 
   692   template <class _InputIterator>
   693   void _M_insert_dispatch(iterator __pos,
   694                           _InputIterator __first, _InputIterator __last,
   695                           const __false_type&) {
   696     _M_insert_range(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
   697   }
   698 
   699   // Check whether it's an integral type.  If so, it's not an iterator.
   700   template <class _InputIterator>
   701   void insert(iterator __position,
   702               _InputIterator __first, _InputIterator __last) {
   703     typedef typename _Is_integer<_InputIterator>::_Integral _Is_Integral;
   704     _M_insert_dispatch(__position, __first, __last, _Is_Integral());
   705   }
   706 #else /* _STLP_MEMBER_TEMPLATES */
   707   void insert(iterator __position,
   708               const_iterator __first, const_iterator __last) {
   709     if (__first == __last) return;
   710     size_type __n = distance(__first, __last);
   711     if (capacity() - size() >= __n) {
   712       __copy_backward(__position, end(), this->_M_finish + __n,
   713                       random_access_iterator_tag(), (difference_type*)0 );
   714       copy(__first, __last, __position);
   715       this->_M_finish += __n;
   716     }
   717     else {
   718       size_type __len = size() + (max)(size(), __n);
   719       unsigned int* __q = this->_M_bit_alloc(__len);
   720       iterator __i = copy(begin(), __position, iterator(__q, 0));
   721       __i = copy(__first, __last, __i);
   722       this->_M_finish = copy(__position, end(), __i);
   723       this->_M_deallocate();
   724       this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   725       this->_M_start = iterator(__q, 0);
   726     }
   727   }
   728 
   729   void insert(iterator __position, const bool* __first, const bool* __last) {
   730     if (__first == __last) return;
   731     size_type __n = distance(__first, __last);
   732     if (capacity() - size() >= __n) {
   733       __copy_backward(__position, end(), this->_M_finish + __n, 
   734                       random_access_iterator_tag(), (difference_type*)0 );
   735       copy(__first, __last, __position);
   736       this->_M_finish += __n;
   737     }
   738     else {
   739       size_type __len = size() + (max)(size(), __n);
   740       unsigned int* __q = this->_M_bit_alloc(__len);
   741       iterator __i = copy(begin(), __position, iterator(__q, 0));
   742       __i = copy(__first, __last, __i);
   743       this->_M_finish = copy(__position, end(), __i);
   744       this->_M_deallocate();
   745       this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   746       this->_M_start = iterator(__q, 0);
   747     }
   748   }
   749 #endif /* _STLP_MEMBER_TEMPLATES */
   750   
   751   void _M_fill_insert(iterator __position, size_type __n, bool __x) {
   752     if (__n == 0) return;
   753     if (capacity() - size() >= __n) {
   754       __copy_backward(__position, end(), this->_M_finish + difference_type(__n), random_access_iterator_tag(), (difference_type*)0 );
   755       fill(__position, __position + difference_type(__n), __x);
   756       this->_M_finish += difference_type(__n);
   757     }
   758     else {
   759       size_type __len = size() + (max)(size(), __n);
   760       unsigned int* __q = this->_M_bit_alloc(__len);
   761       iterator __i = copy(begin(), __position, iterator(__q, 0));
   762       fill_n(__i, __n, __x);
   763       this->_M_finish = copy(__position, end(), __i + difference_type(__n));
   764       this->_M_deallocate();
   765       this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   766       this->_M_start = iterator(__q, 0);
   767     }
   768   }
   769 
   770   void insert(iterator __position, size_type __n, bool __x) {
   771     _M_fill_insert(__position, __n, __x);
   772   }
   773 
   774   void pop_back() {
   775       --this->_M_finish; 
   776   }
   777   iterator erase(iterator __position) {
   778     if (__position + 1 != end())
   779       copy(__position + 1, end(), __position);
   780       --this->_M_finish;
   781     return __position;
   782   }
   783   iterator erase(iterator __first, iterator __last) {
   784     this->_M_finish = copy(__last, end(), __first);
   785     return __first;
   786   }
   787   void resize(size_type __new_size, bool __x = bool()) {
   788     if (__new_size < size()) 
   789       erase(begin() + difference_type(__new_size), end());
   790     else
   791       insert(end(), __new_size - size(), __x);
   792   }
   793   void flip() {
   794     for (unsigned int* __p = this->_M_start._M_p; __p != this->_M_end_of_storage._M_data; ++__p)
   795       *__p = ~*__p;
   796   }
   797 
   798   void clear() { erase(begin(), end()); }
   799 };
   800 
   801 # if defined  ( _STLP_NO_BOOL ) || defined (__HP_aCC) // fixed soon (03/17/2000)
   802  
   803 #define _STLP_TEMPLATE_HEADER __BVEC_TMPL_HEADER
   804 #define _STLP_TEMPLATE_CONTAINER __BVECTOR_QUALIFIED
   805 #include <stl/_relops_cont.h>
   806 #undef _STLP_TEMPLATE_CONTAINER
   807 #undef _STLP_TEMPLATE_HEADER
   808   
   809 # endif /* NO_BOOL */
   810   
   811 #if !defined (_STLP_NO_BOOL)
   812 // This typedef is non-standard.  It is provided for backward compatibility.
   813   typedef __WORKAROUND_DBG_RENAME(vector) <bool, allocator<bool> > bit_vector;
   814 #endif
   815 
   816 _STLP_END_NAMESPACE
   817 
   818 #undef _Alloc
   819 #undef _STLP_VECBOOL_TEMPLATE
   820 #undef __BVECTOR
   821 #undef __BVECTOR_QUALIFIED
   822 #undef __BVEC_TMPL_HEADER
   823 
   824 # undef __WORD_BIT
   825 
   826 #endif /* _STLP_INTERNAL_BVECTOR_H */
   827 
   828 // Local Variables:
   829 // mode:C++
   830 // End:
   831