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