epoc32/include/stdapis/stlportv5/stl/_bvector.h
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/stlportv5/stl/_bvector.h	Wed Mar 31 12:27:01 2010 +0100
     1.3 @@ -0,0 +1,831 @@
     1.4 +/*
     1.5 + *
     1.6 + * Copyright (c) 1994
     1.7 + * Hewlett-Packard Company
     1.8 + *
     1.9 + * Copyright (c) 1996,1997
    1.10 + * Silicon Graphics Computer Systems, Inc.
    1.11 + *
    1.12 + * Copyright (c) 1997
    1.13 + * Moscow Center for SPARC Technology
    1.14 + *
    1.15 + * Copyright (c) 1999 
    1.16 + * Boris Fomitchev
    1.17 + *
    1.18 + * This material is provided "as is", with absolutely no warranty expressed
    1.19 + * or implied. Any use is at your own risk.
    1.20 + *
    1.21 + * Permission to use or copy this software for any purpose is hereby granted 
    1.22 + * without fee, provided the above notices are retained on all copies.
    1.23 + * Permission to modify the code and to distribute modified code is granted,
    1.24 + * provided the above notices are retained, and a notice that the code was
    1.25 + * modified is included with the above copyright notice.
    1.26 + *
    1.27 + */
    1.28 +
    1.29 +/* NOTE: This is an internal header file, included by other STL headers.
    1.30 + *   You should not attempt to use it directly.
    1.31 + */
    1.32 +
    1.33 +#ifndef _STLP_INTERNAL_BVECTOR_H
    1.34 +#define _STLP_INTERNAL_BVECTOR_H
    1.35 +
    1.36 +#ifndef _STLP_INTERNAL_VECTOR_H
    1.37 +# include <stl/_vector.h>
    1.38 +# endif
    1.39 +
    1.40 +#ifndef __WORD_BIT
    1.41 +#define __WORD_BIT (int(CHAR_BIT*sizeof(unsigned int)))
    1.42 +#endif
    1.43 +
    1.44 +_STLP_BEGIN_NAMESPACE 
    1.45 +
    1.46 +struct _Bit_reference {
    1.47 +  unsigned int* _M_p;
    1.48 +  unsigned int _M_mask;
    1.49 +  _Bit_reference(unsigned int* __x, unsigned int __y) 
    1.50 +    : _M_p(__x), _M_mask(__y) {}
    1.51 +
    1.52 +public:
    1.53 +  _Bit_reference() : _M_p(0), _M_mask(0) {}
    1.54 +
    1.55 +  operator bool() const { 
    1.56 +	  return !(!(*_M_p & _M_mask)); 
    1.57 +  }
    1.58 +  _Bit_reference& operator=(bool __x) {
    1.59 +    if (__x)  *_M_p |= _M_mask;
    1.60 +    else      *_M_p &= ~_M_mask;
    1.61 +    return *this;
    1.62 +  }
    1.63 +  _Bit_reference& operator=(const _Bit_reference& __x) {
    1.64 +	  return *this = bool(__x); 
    1.65 +  }
    1.66 +  bool operator==(const _Bit_reference& __x) const {
    1.67 +	  return bool(*this) == bool(__x); 
    1.68 +  }
    1.69 +  bool operator<(const _Bit_reference& __x) const {
    1.70 +    return !bool(*this) && bool(__x);
    1.71 +  }
    1.72 +
    1.73 +  _Bit_reference& operator |= (bool __x) {
    1.74 +	  if (__x)
    1.75 +		  *_M_p |= _M_mask;
    1.76 +	  return *this;
    1.77 +  }
    1.78 +  _Bit_reference& operator &= (bool __x) {
    1.79 +	  if (!__x)
    1.80 +		  *_M_p &= ~_M_mask;
    1.81 +	  return *this;
    1.82 +  }
    1.83 +  void flip() { *_M_p ^= _M_mask; }
    1.84 +};
    1.85 +
    1.86 +
    1.87 +inline void swap(_Bit_reference& __x, _Bit_reference& __y)
    1.88 +{
    1.89 +  bool __tmp = (bool)__x;
    1.90 +  __x = __y;
    1.91 +  __y = __tmp;
    1.92 +}
    1.93 +
    1.94 +struct _Bit_iterator_base;
    1.95 +
    1.96 +struct _Bit_iterator_base
    1.97 +{
    1.98 +  typedef ptrdiff_t difference_type;
    1.99 +
   1.100 +  unsigned int* _M_p;
   1.101 +  unsigned int  _M_offset;
   1.102 +
   1.103 +  void _M_bump_up() {
   1.104 +    if (_M_offset++ == __WORD_BIT - 1) {
   1.105 +      _M_offset = 0;
   1.106 +      ++_M_p;
   1.107 +    }
   1.108 +  }
   1.109 +
   1.110 +  void _M_bump_down() {
   1.111 +    if (_M_offset-- == 0) {
   1.112 +      _M_offset = __WORD_BIT - 1;
   1.113 +      --_M_p;
   1.114 +    }
   1.115 +  }
   1.116 +
   1.117 +  _Bit_iterator_base() : _M_p(0), _M_offset(0) {}
   1.118 +  _Bit_iterator_base(unsigned int* __x, unsigned int __y) : _M_p(__x), _M_offset(__y) {}
   1.119 +  //  _Bit_iterator_base( const _Bit_iterator_base& __x) : _M_p(__x._M_p), _M_offset(__x._M_offset) {}
   1.120 +  //  _Bit_iterator_base& operator = ( const _Bit_iterator_base& __x) { _M_p = __x._M_p ; _M_offset = __x._M_offset ; return *this; }
   1.121 +
   1.122 +  void _M_advance (difference_type __i) {
   1.123 +    difference_type __n = __i + _M_offset;
   1.124 +    _M_p += __n / __WORD_BIT;
   1.125 +    __n = __n % __WORD_BIT;
   1.126 +    if (__n < 0) {
   1.127 +      _M_offset = (unsigned int) __n + __WORD_BIT;
   1.128 +      --_M_p;
   1.129 +    } else
   1.130 +      _M_offset = (unsigned int) __n;
   1.131 +  }
   1.132 +
   1.133 +  difference_type _M_subtract(const _Bit_iterator_base& __x) const {
   1.134 +    return __WORD_BIT * (_M_p - __x._M_p) + _M_offset - __x._M_offset;
   1.135 +  }
   1.136 +};
   1.137 +
   1.138 +inline bool  _STLP_CALL operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
   1.139 +  return __y._M_p == __x._M_p && __y._M_offset == __x._M_offset;
   1.140 +}
   1.141 +inline bool  _STLP_CALL operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
   1.142 +  return __y._M_p != __x._M_p || __y._M_offset != __x._M_offset;
   1.143 +}
   1.144 +
   1.145 +inline bool _STLP_CALL operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
   1.146 +  return __x._M_p < __y._M_p || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset);
   1.147 +}
   1.148 +
   1.149 +inline bool _STLP_CALL operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)  { 
   1.150 +  return operator <(__y , __x); 
   1.151 +}
   1.152 +inline bool _STLP_CALL operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 
   1.153 +  return !(__y < __x); 
   1.154 +}
   1.155 +inline bool _STLP_CALL operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { 
   1.156 +  return !(__x < __y); 
   1.157 +}
   1.158 +
   1.159 +template <class _Ref, class _Ptr>
   1.160 +struct _Bit_iter : public _Bit_iterator_base
   1.161 +{
   1.162 +  typedef _Ref  reference;
   1.163 +  typedef _Ptr  pointer;
   1.164 +  typedef _Bit_iter<_Ref, _Ptr> _Self;
   1.165 +  typedef random_access_iterator_tag iterator_category;
   1.166 +  typedef bool value_type;
   1.167 +  typedef ptrdiff_t difference_type;
   1.168 +  typedef size_t size_type;
   1.169 +
   1.170 +  _Bit_iter(unsigned int* __x, unsigned int __y) : _Bit_iterator_base(__x, __y) {}
   1.171 +  _Bit_iter() {}
   1.172 +
   1.173 +  _Bit_iter(const _Bit_iter<_Bit_reference, _Bit_reference*>& __x): 
   1.174 +    _Bit_iterator_base((const _Bit_iterator_base&)__x) {}
   1.175 +
   1.176 +  //  _Self& operator = (const _Bit_iter<_Bit_reference, _Bit_reference*>& __x)
   1.177 +  //   { (_Bit_iterator_base&)*this = (const _Bit_iterator_base&)__x; return *this; }
   1.178 +
   1.179 +  reference operator*() const { 
   1.180 +    return _Bit_reference(_M_p, 1UL << _M_offset); 
   1.181 +  }
   1.182 +  _Self& operator++() {
   1.183 +    _M_bump_up();
   1.184 +    return *this;
   1.185 +  }
   1.186 +  _Self operator++(int) {
   1.187 +    _Self __tmp = *this;
   1.188 +    _M_bump_up();
   1.189 +    return __tmp;
   1.190 +  }
   1.191 +  _Self& operator--() {
   1.192 +    _M_bump_down();
   1.193 +    return *this;
   1.194 +  }
   1.195 +  _Self operator--(int) {
   1.196 +    _Self __tmp = *this;
   1.197 +    _M_bump_down();
   1.198 +    return __tmp;
   1.199 +  }
   1.200 +  _Self& operator+=(difference_type __i) {
   1.201 +    _M_advance(__i);
   1.202 +    return *this;
   1.203 +  }
   1.204 +  _Self& operator-=(difference_type __i) {
   1.205 +    *this += -__i;
   1.206 +    return *this;
   1.207 +  }
   1.208 +  _Self operator+(difference_type __i) const {
   1.209 +    _Self __tmp = *this;
   1.210 +    return __tmp += __i;
   1.211 +  }
   1.212 +  _Self operator-(difference_type __i) const {
   1.213 +    _Self __tmp = *this;
   1.214 +    return __tmp -= __i;
   1.215 +  }
   1.216 +  difference_type operator-(const _Self& __x) const {
   1.217 +    return _M_subtract(__x);
   1.218 +  }
   1.219 +  reference operator[](difference_type __i) { return *(*this + __i); }
   1.220 +};
   1.221 +
   1.222 +template <class _Ref, class _Ptr>
   1.223 +inline _Bit_iter<_Ref,_Ptr>  _STLP_CALL
   1.224 +operator+(ptrdiff_t __n, const _Bit_iter<_Ref, _Ptr>& __x) {
   1.225 +   return __x + __n;
   1.226 +}
   1.227 +
   1.228 +# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
   1.229 +inline random_access_iterator_tag  iterator_category(const _Bit_iterator_base&) {return random_access_iterator_tag();}
   1.230 +inline ptrdiff_t* distance_type(const _Bit_iterator_base&) {return (ptrdiff_t*)0;}
   1.231 +inline bool* value_type(const _Bit_iter<_Bit_reference, _Bit_reference*>&) {return (bool*)0;}
   1.232 +inline bool* value_type(const _Bit_iter<bool, const bool*>&) {return (bool*)0;}
   1.233 +# endif
   1.234 +
   1.235 +typedef _Bit_iter<bool, const bool*> _Bit_const_iterator;
   1.236 +typedef _Bit_iter<_Bit_reference, _Bit_reference*> _Bit_iterator;
   1.237 +
   1.238 +// Bit-vector base class, which encapsulates the difference between
   1.239 +//  old SGI-style allocators and standard-conforming allocators.
   1.240 +
   1.241 +
   1.242 +template <class _Alloc>
   1.243 +class _Bvector_base
   1.244 +{
   1.245 +public:
   1.246 +  _STLP_FORCE_ALLOCATORS(bool, _Alloc)
   1.247 +  typedef typename _Alloc_traits<bool, _Alloc>::allocator_type allocator_type;
   1.248 +  typedef unsigned int __chunk_type;
   1.249 +  typedef typename _Alloc_traits<__chunk_type, 
   1.250 +          _Alloc>::allocator_type __chunk_allocator_type;
   1.251 +  allocator_type get_allocator() const { 
   1.252 +    return _STLP_CONVERT_ALLOCATOR((const __chunk_allocator_type&)_M_end_of_storage, bool); 
   1.253 +  }
   1.254 +  static allocator_type __get_dfl_allocator() { return allocator_type(); }
   1.255 +   
   1.256 +  _Bvector_base(const allocator_type& __a)
   1.257 +    : _M_start(), _M_finish(), _M_end_of_storage(_STLP_CONVERT_ALLOCATOR(__a, __chunk_type),
   1.258 +						 (__chunk_type*)0) {
   1.259 +  }
   1.260 +  ~_Bvector_base() { _M_deallocate();
   1.261 +  }
   1.262 +
   1.263 +protected:
   1.264 +
   1.265 +  unsigned int* _M_bit_alloc(size_t __n) 
   1.266 +    { return _M_end_of_storage.allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
   1.267 +  void _M_deallocate() {
   1.268 +    if (_M_start._M_p)
   1.269 +      _M_end_of_storage.deallocate(_M_start._M_p,
   1.270 +				   _M_end_of_storage._M_data - _M_start._M_p);
   1.271 +  }
   1.272 +
   1.273 +  _Bit_iterator _M_start;
   1.274 +  _Bit_iterator _M_finish;
   1.275 +  _STLP_alloc_proxy<__chunk_type*, __chunk_type, __chunk_allocator_type> _M_end_of_storage;  
   1.276 +};
   1.277 +
   1.278 +
   1.279 +// The next few lines are confusing.  What we're doing is declaring a
   1.280 +//  partial specialization of vector<T, Alloc> if we have the necessary
   1.281 +//  compiler support.  Otherwise, we define a class bit_vector which uses
   1.282 +//  the default allocator. 
   1.283 +
   1.284 +#if defined(_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined(_STLP_NO_BOOL) && ! defined (__SUNPRO_CC)
   1.285 +# define _STLP_VECBOOL_TEMPLATE
   1.286 +# define __BVEC_TMPL_HEADER template <class _Alloc>
   1.287 +#else
   1.288 +# undef _STLP_VECBOOL_TEMPLATE
   1.289 +# ifdef _STLP_NO_BOOL
   1.290 +#  define __BVEC_TMPL_HEADER
   1.291 +# else
   1.292 +#  define __BVEC_TMPL_HEADER _STLP_TEMPLATE_NULL
   1.293 +# endif
   1.294 +# if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))			//*TY 12/17/2000 - 
   1.295 +#  define _Alloc _STLP_DEFAULT_ALLOCATOR(bool)
   1.296 +# else
   1.297 +#  define _Alloc allocator<bool>
   1.298 +# endif
   1.299 +#endif
   1.300 +
   1.301 +#ifdef _STLP_NO_BOOL
   1.302 +# define __BVECTOR_QUALIFIED bit_vector
   1.303 +# define __BVECTOR           bit_vector
   1.304 +#else
   1.305 +# ifdef _STLP_VECBOOL_TEMPLATE
   1.306 +#  define __BVECTOR_QUALIFIED __WORKAROUND_DBG_RENAME(vector) <bool, _Alloc>
   1.307 +# else
   1.308 +#  define __BVECTOR_QUALIFIED __WORKAROUND_DBG_RENAME(vector) <bool, allocator<bool> >
   1.309 +# endif
   1.310 +#if defined (_STLP_PARTIAL_SPEC_NEEDS_TEMPLATE_ARGS)
   1.311 +# define __BVECTOR __BVECTOR_QUALIFIED
   1.312 +#else
   1.313 +# define __BVECTOR __WORKAROUND_DBG_RENAME(vector)
   1.314 +#endif
   1.315 +#endif
   1.316 +
   1.317 +
   1.318 +__BVEC_TMPL_HEADER
   1.319 +class __BVECTOR_QUALIFIED : public _Bvector_base<_Alloc >
   1.320 +{
   1.321 +  typedef _Bvector_base<_Alloc > _Base;
   1.322 +  typedef __BVECTOR_QUALIFIED _Self;
   1.323 +public:
   1.324 +  typedef bool value_type;
   1.325 +  typedef size_t size_type;
   1.326 +  typedef ptrdiff_t difference_type; 
   1.327 +  typedef _Bit_reference reference;
   1.328 +  typedef bool const_reference;
   1.329 +  typedef _Bit_reference* pointer;
   1.330 +  typedef const bool* const_pointer;
   1.331 +  typedef random_access_iterator_tag _Iterator_category;
   1.332 +
   1.333 +  typedef _Bit_iterator                iterator;
   1.334 +  typedef _Bit_const_iterator          const_iterator;
   1.335 +
   1.336 +#if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
   1.337 +  typedef _STLP_STD::reverse_iterator<const_iterator> const_reverse_iterator;
   1.338 +  typedef _STLP_STD::reverse_iterator<iterator> reverse_iterator;
   1.339 +#else /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   1.340 +# if defined (_STLP_MSVC50_COMPATIBILITY)
   1.341 +  typedef _STLP_STD::reverse_iterator<const_iterator, value_type, const_reference, 
   1.342 +  const_pointer, difference_type> const_reverse_iterator;
   1.343 +  typedef _STLP_STD::reverse_iterator<iterator, value_type, reference, reference*, 
   1.344 +  difference_type> reverse_iterator;
   1.345 +# else
   1.346 +  typedef _STLP_STD::reverse_iterator<const_iterator, value_type, const_reference, 
   1.347 +                                  difference_type> const_reverse_iterator;
   1.348 +  typedef _STLP_STD::reverse_iterator<iterator, value_type, reference, difference_type>
   1.349 +          reverse_iterator;
   1.350 +# endif
   1.351 +#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
   1.352 +
   1.353 +# ifdef _STLP_VECBOOL_TEMPLATE
   1.354 +  typedef typename _Bvector_base<_Alloc >::allocator_type allocator_type;
   1.355 +  typedef typename _Bvector_base<_Alloc >::__chunk_type __chunk_type ;
   1.356 +# else
   1.357 +  typedef _Bvector_base<_Alloc >::allocator_type allocator_type;
   1.358 +  typedef _Bvector_base<_Alloc >::__chunk_type __chunk_type ;
   1.359 +# endif
   1.360 +
   1.361 +protected:
   1.362 +
   1.363 +  void _M_initialize(size_type __n) {
   1.364 +    unsigned int* __q = this->_M_bit_alloc(__n);
   1.365 +    this->_M_end_of_storage._M_data = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
   1.366 +    this->_M_start = iterator(__q, 0);
   1.367 +    this->_M_finish = this->_M_start + difference_type(__n);
   1.368 +  }
   1.369 +  void _M_insert_aux(iterator __position, bool __x) {
   1.370 +    if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
   1.371 +      __copy_backward(__position, this->_M_finish, this->_M_finish + 1, random_access_iterator_tag(), (difference_type*)0 );
   1.372 +      *__position = __x;
   1.373 +      ++this->_M_finish;
   1.374 +    }
   1.375 +    else {
   1.376 +      size_type __len = size() ? 2 * size() : __WORD_BIT;
   1.377 +      unsigned int* __q = this->_M_bit_alloc(__len);
   1.378 +      iterator __i = copy(begin(), __position, iterator(__q, 0));
   1.379 +      *__i++ = __x;
   1.380 +      this->_M_finish = copy(__position, end(), __i);
   1.381 +      this->_M_deallocate();
   1.382 +      this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   1.383 +      this->_M_start = iterator(__q, 0);
   1.384 +    }
   1.385 +  }
   1.386 +
   1.387 +#ifdef _STLP_MEMBER_TEMPLATES
   1.388 +  template <class _InputIterator>
   1.389 +  void _M_initialize_range(_InputIterator __first, _InputIterator __last,
   1.390 +			const input_iterator_tag &) {
   1.391 +    this->_M_start = iterator();
   1.392 +    this->_M_finish = iterator();
   1.393 +    this->_M_end_of_storage._M_data = 0;
   1.394 +    for ( ; __first != __last; ++__first) 
   1.395 +      push_back(*__first);
   1.396 +  }
   1.397 +
   1.398 +  template <class _ForwardIterator>
   1.399 +  void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
   1.400 +                           const forward_iterator_tag &) {
   1.401 +    size_type __n = distance(__first, __last);
   1.402 +    _M_initialize(__n);
   1.403 +    //    copy(__first, __last, _M_start);
   1.404 +    copy(__first, __last, this->_M_start); // dwa 12/22/99 -- resolving ambiguous reference.
   1.405 +  }
   1.406 +
   1.407 +  template <class _InputIterator>
   1.408 +  void _M_insert_range(iterator __pos,
   1.409 +                       _InputIterator __first, _InputIterator __last,
   1.410 +                       const input_iterator_tag &) {
   1.411 +    for ( ; __first != __last; ++__first) {
   1.412 +      __pos = insert(__pos, *__first);
   1.413 +      ++__pos;
   1.414 +    }
   1.415 +  }
   1.416 +
   1.417 +  template <class _ForwardIterator>
   1.418 +  void _M_insert_range(iterator __position,
   1.419 +                       _ForwardIterator __first, _ForwardIterator __last,
   1.420 +                       const forward_iterator_tag &) {
   1.421 +    if (__first != __last) {
   1.422 +      size_type __n = distance(__first, __last);
   1.423 +      if (capacity() - size() >= __n) {
   1.424 +        __copy_backward(__position, end(), this->_M_finish + difference_type(__n), random_access_iterator_tag(), (difference_type*)0 );
   1.425 +        copy(__first, __last, __position);
   1.426 +        this->_M_finish += difference_type(__n);
   1.427 +      }
   1.428 +      else {
   1.429 +        size_type __len = size() + (max)(size(), __n);
   1.430 +        unsigned int* __q = this->_M_bit_alloc(__len);
   1.431 +        iterator __i = copy(begin(), __position, iterator(__q, 0));
   1.432 +        __i = copy(__first, __last, __i);
   1.433 +        this->_M_finish = copy(__position, end(), __i);
   1.434 +        this->_M_deallocate();
   1.435 +        this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   1.436 +        this->_M_start = iterator(__q, 0);
   1.437 +      }
   1.438 +    }
   1.439 +  }      
   1.440 +
   1.441 +#endif /* _STLP_MEMBER_TEMPLATES */
   1.442 +
   1.443 +public:
   1.444 +  iterator begin() { return this->_M_start; }
   1.445 +  const_iterator begin() const { return this->_M_start; }
   1.446 +  iterator end() { return this->_M_finish; }
   1.447 +  const_iterator end() const { return this->_M_finish; }
   1.448 +
   1.449 +  reverse_iterator rbegin() { return reverse_iterator(end()); }
   1.450 +  const_reverse_iterator rbegin() const { 
   1.451 +    return const_reverse_iterator(end()); 
   1.452 +  }
   1.453 +  reverse_iterator rend() { return reverse_iterator(begin()); }
   1.454 +  const_reverse_iterator rend() const { 
   1.455 +    return const_reverse_iterator(begin()); 
   1.456 +  }
   1.457 +
   1.458 +  size_type size() const { return size_type(end() - begin()); }
   1.459 +  size_type max_size() const { return size_type(-1); }
   1.460 +  size_type capacity() const {
   1.461 +    return size_type(const_iterator(this->_M_end_of_storage._M_data, 0) - begin());
   1.462 +  }
   1.463 +  bool empty() const { return begin() == end(); }
   1.464 +  reference operator[](size_type __n) 
   1.465 +  { return *(begin() + difference_type(__n)); }
   1.466 +  const_reference operator[](size_type __n) const 
   1.467 +  { return *(begin() + difference_type(__n)); }
   1.468 +
   1.469 +  void _M_range_check(size_type __n) const {
   1.470 +    if (__n >= this->size())
   1.471 +      __stl_throw_range_error("vector<bool>");
   1.472 +  }
   1.473 +
   1.474 +  reference at(size_type __n)
   1.475 +    { _M_range_check(__n); return (*this)[__n]; }
   1.476 +  const_reference at(size_type __n) const
   1.477 +    { _M_range_check(__n); return (*this)[__n]; }
   1.478 +
   1.479 +  explicit __BVECTOR(const allocator_type& __a = allocator_type())
   1.480 +    : _Bvector_base<_Alloc >(__a) {
   1.481 +    _STLP_POP_IF_CHECK
   1.482 +  }
   1.483 +
   1.484 +  __BVECTOR(size_type __n, bool __val,
   1.485 +            const allocator_type& __a = 
   1.486 +	    allocator_type())
   1.487 +    : _Bvector_base<_Alloc >(__a)
   1.488 +  {
   1.489 +    _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   1.490 +    _M_initialize(__n);
   1.491 +    fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __val ? ~0 : 0);
   1.492 +    _STLP_POP_CLEANUP_ITEM	  
   1.493 +  }
   1.494 +
   1.495 +  explicit __BVECTOR(size_type __n)
   1.496 +    : _Bvector_base<_Alloc >(allocator_type())
   1.497 +  {
   1.498 +    _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   1.499 +    _M_initialize(__n);
   1.500 +    fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), 0);
   1.501 +    _STLP_POP_CLEANUP_ITEM  
   1.502 +  }
   1.503 +
   1.504 +  __BVECTOR(const _Self& __x) : _Bvector_base<_Alloc >(__x.get_allocator()) {
   1.505 +    _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   1.506 +    _M_initialize(__x.size());
   1.507 +    copy(__x.begin(), __x.end(), this->_M_start);
   1.508 +    _STLP_POP_CLEANUP_ITEM  
   1.509 +  }
   1.510 +
   1.511 +#if defined (_STLP_MEMBER_TEMPLATES)
   1.512 +  template <class _Integer>
   1.513 +  void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
   1.514 +    _M_initialize(__n);
   1.515 +    fill(this->_M_start._M_p, this->_M_end_of_storage._M_data, __x ? ~0 : 0);
   1.516 +  }
   1.517 +    
   1.518 +  template <class _InputIterator>
   1.519 +  void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
   1.520 +                              const __false_type&) {
   1.521 +    _M_initialize_range(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
   1.522 +  }
   1.523 +# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
   1.524 +  // Check whether it's an integral type.  If so, it's not an iterator.
   1.525 +  template <class _InputIterator>
   1.526 +  __BVECTOR(_InputIterator __first, _InputIterator __last)
   1.527 +    : _Base(allocator_type())
   1.528 +  {
   1.529 +    typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
   1.530 +    _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   1.531 +    _M_initialize_dispatch(__first, __last, _Integral());
   1.532 +    _STLP_POP_CLEANUP_ITEM  
   1.533 +  }
   1.534 +# endif
   1.535 +  template <class _InputIterator>
   1.536 +  __BVECTOR(_InputIterator __first, _InputIterator __last,
   1.537 +            const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
   1.538 +    : _Base(__a)
   1.539 +  {
   1.540 +    typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
   1.541 +    _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   1.542 +    _M_initialize_dispatch(__first, __last, _Integral());
   1.543 +    _STLP_POP_CLEANUP_ITEM  
   1.544 +  }
   1.545 +#else /* _STLP_MEMBER_TEMPLATES */
   1.546 +  __BVECTOR(const_iterator __first, const_iterator __last,
   1.547 +            const allocator_type& __a = allocator_type())
   1.548 +    : _Bvector_base<_Alloc >(__a)
   1.549 +  {
   1.550 +    _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   1.551 +    size_type __n = distance(__first, __last);
   1.552 +    _M_initialize(__n);
   1.553 +    copy(__first, __last, this->_M_start);
   1.554 +    _STLP_POP_CLEANUP_ITEM  
   1.555 +  }
   1.556 +  __BVECTOR(const bool* __first, const bool* __last,
   1.557 +            const allocator_type& __a = allocator_type())
   1.558 +    : _Bvector_base<_Alloc >(__a)
   1.559 +  {
   1.560 +    size_type __n = distance(__first, __last);
   1.561 +    _STLP_PUSH_CLEANUP_ITEM(_Base, this)  
   1.562 +    _M_initialize(__n);
   1.563 +    copy(__first, __last, this->_M_start);
   1.564 +    _STLP_POP_CLEANUP_ITEM  
   1.565 +  }
   1.566 +#endif /* _STLP_MEMBER_TEMPLATES */
   1.567 +
   1.568 +  ~__BVECTOR() { }
   1.569 +
   1.570 +  __BVECTOR_QUALIFIED& operator=(const __BVECTOR_QUALIFIED& __x) {
   1.571 +    if (&__x == this) return *this;
   1.572 +    if (__x.size() > capacity()) {
   1.573 +      this->_M_deallocate();
   1.574 +      _M_initialize(__x.size());
   1.575 +    }
   1.576 +    copy(__x.begin(), __x.end(), begin());
   1.577 +    this->_M_finish = begin() + difference_type(__x.size());
   1.578 +    return *this;
   1.579 +  }
   1.580 +
   1.581 +#ifdef _STLP_USE_TRAP_LEAVE
   1.582 +public:
   1.583 +  static void* operator new (size_t __n, TLeave) { return _STLP_StackHelper<bool>::_NewLC(__n); }
   1.584 +  static void* operator new (size_t __n) { return _STLP_StackHelper<bool>::_NewLC(__n); }
   1.585 +#endif
   1.586 +
   1.587 +  // assign(), a generalized assignment member function.  Two
   1.588 +  // versions: one that takes a count, and one that takes a range.
   1.589 +  // The range version is a member template, so we dispatch on whether
   1.590 +  // or not the type is an integer.
   1.591 +
   1.592 +  void _M_fill_assign(size_t __n, bool __x) {
   1.593 +    if (__n > size()) {
   1.594 +      fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
   1.595 +      insert(end(), __n - size(), __x);
   1.596 +    }
   1.597 +    else {
   1.598 +      erase(begin() + __n, end());
   1.599 +      fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
   1.600 +    }
   1.601 +  }
   1.602 +  void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
   1.603 +
   1.604 +#ifdef _STLP_MEMBER_TEMPLATES
   1.605 +
   1.606 +  template <class _InputIterator>
   1.607 +  void assign(_InputIterator __first, _InputIterator __last) {
   1.608 +    typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
   1.609 +    _M_assign_dispatch(__first, __last, _Integral());
   1.610 +  }
   1.611 +
   1.612 +  template <class _Integer>
   1.613 +  void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
   1.614 +    { _M_fill_assign((size_t) __n, (bool) __val); }
   1.615 +
   1.616 +  template <class _InputIter>
   1.617 +  void _M_assign_dispatch(_InputIter __first, _InputIter __last, const __false_type&)
   1.618 +    { _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
   1.619 +
   1.620 +  template <class _InputIterator>
   1.621 +  void _M_assign_aux(_InputIterator __first, _InputIterator __last,
   1.622 +                     const input_iterator_tag &) {
   1.623 +    iterator __cur = begin();
   1.624 +    for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
   1.625 +      *__cur = *__first;
   1.626 +    if (__first == __last)
   1.627 +      erase(__cur, end());
   1.628 +    else
   1.629 +      insert(end(), __first, __last);
   1.630 +  }
   1.631 +
   1.632 +  template <class _ForwardIterator>
   1.633 +  void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
   1.634 +                     const forward_iterator_tag &) {
   1.635 +    size_type __len = distance(__first, __last);
   1.636 +    if (__len < size())
   1.637 +      erase(copy(__first, __last, begin()), end());
   1.638 +    else {
   1.639 +      _ForwardIterator __mid = __first;
   1.640 +      advance(__mid, size());
   1.641 +      copy(__first, __mid, begin());
   1.642 +      insert(end(), __mid, __last);
   1.643 +    }
   1.644 +  }    
   1.645 +
   1.646 +#endif /* _STLP_MEMBER_TEMPLATES */
   1.647 +
   1.648 +  void reserve(size_type __n) {
   1.649 +    if (capacity() < __n) {
   1.650 +      unsigned int* __q = this->_M_bit_alloc(__n);
   1.651 +      _Bit_iterator __z(__q, 0);
   1.652 +      this->_M_finish = copy(begin(), end(), __z);
   1.653 +      this->_M_deallocate();
   1.654 +      this->_M_start = iterator(__q, 0);
   1.655 +      this->_M_end_of_storage._M_data = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
   1.656 +    }
   1.657 +  }
   1.658 +
   1.659 +  reference front() { return *begin(); }
   1.660 +  const_reference front() const { return *begin(); }
   1.661 +  reference back() { return *(end() - 1); }
   1.662 +  const_reference back() const { return *(end() - 1); }
   1.663 +  void push_back(bool __x) {
   1.664 +    if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
   1.665 +      *(this->_M_finish) = __x;
   1.666 +      ++this->_M_finish;
   1.667 +    }
   1.668 +    else
   1.669 +      _M_insert_aux(end(), __x);
   1.670 +  }
   1.671 +  void swap(__BVECTOR_QUALIFIED& __x) {
   1.672 +    _STLP_STD::swap(this->_M_start, __x._M_start);
   1.673 +    _STLP_STD::swap(this->_M_finish, __x._M_finish);
   1.674 +    _STLP_STD::swap(this->_M_end_of_storage, __x._M_end_of_storage);
   1.675 +  }
   1.676 +  iterator insert(iterator __position, bool __x = bool()) {
   1.677 +    difference_type __n = __position - begin();
   1.678 +    if (this->_M_finish._M_p != this->_M_end_of_storage._M_data && __position == end()) {
   1.679 +      *(this->_M_finish) = __x;
   1.680 +      ++this->_M_finish;
   1.681 +    }
   1.682 +    else
   1.683 +      _M_insert_aux(__position, __x);
   1.684 +    return begin() + __n;
   1.685 +  }
   1.686 +
   1.687 +#if defined ( _STLP_MEMBER_TEMPLATES )
   1.688 +
   1.689 +  template <class _Integer>
   1.690 +  void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
   1.691 +                          const __true_type&) {
   1.692 +    _M_fill_insert(__pos, (size_type) __n, (bool) __x);
   1.693 +  }
   1.694 +
   1.695 +  template <class _InputIterator>
   1.696 +  void _M_insert_dispatch(iterator __pos,
   1.697 +                          _InputIterator __first, _InputIterator __last,
   1.698 +                          const __false_type&) {
   1.699 +    _M_insert_range(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
   1.700 +  }
   1.701 +
   1.702 +  // Check whether it's an integral type.  If so, it's not an iterator.
   1.703 +  template <class _InputIterator>
   1.704 +  void insert(iterator __position,
   1.705 +              _InputIterator __first, _InputIterator __last) {
   1.706 +    typedef typename _Is_integer<_InputIterator>::_Integral _Is_Integral;
   1.707 +    _M_insert_dispatch(__position, __first, __last, _Is_Integral());
   1.708 +  }
   1.709 +#else /* _STLP_MEMBER_TEMPLATES */
   1.710 +  void insert(iterator __position,
   1.711 +              const_iterator __first, const_iterator __last) {
   1.712 +    if (__first == __last) return;
   1.713 +    size_type __n = distance(__first, __last);
   1.714 +    if (capacity() - size() >= __n) {
   1.715 +      __copy_backward(__position, end(), this->_M_finish + __n,
   1.716 +                      random_access_iterator_tag(), (difference_type*)0 );
   1.717 +      copy(__first, __last, __position);
   1.718 +      this->_M_finish += __n;
   1.719 +    }
   1.720 +    else {
   1.721 +      size_type __len = size() + (max)(size(), __n);
   1.722 +      unsigned int* __q = this->_M_bit_alloc(__len);
   1.723 +      iterator __i = copy(begin(), __position, iterator(__q, 0));
   1.724 +      __i = copy(__first, __last, __i);
   1.725 +      this->_M_finish = copy(__position, end(), __i);
   1.726 +      this->_M_deallocate();
   1.727 +      this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   1.728 +      this->_M_start = iterator(__q, 0);
   1.729 +    }
   1.730 +  }
   1.731 +
   1.732 +  void insert(iterator __position, const bool* __first, const bool* __last) {
   1.733 +    if (__first == __last) return;
   1.734 +    size_type __n = distance(__first, __last);
   1.735 +    if (capacity() - size() >= __n) {
   1.736 +      __copy_backward(__position, end(), this->_M_finish + __n, 
   1.737 +                      random_access_iterator_tag(), (difference_type*)0 );
   1.738 +      copy(__first, __last, __position);
   1.739 +      this->_M_finish += __n;
   1.740 +    }
   1.741 +    else {
   1.742 +      size_type __len = size() + (max)(size(), __n);
   1.743 +      unsigned int* __q = this->_M_bit_alloc(__len);
   1.744 +      iterator __i = copy(begin(), __position, iterator(__q, 0));
   1.745 +      __i = copy(__first, __last, __i);
   1.746 +      this->_M_finish = copy(__position, end(), __i);
   1.747 +      this->_M_deallocate();
   1.748 +      this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   1.749 +      this->_M_start = iterator(__q, 0);
   1.750 +    }
   1.751 +  }
   1.752 +#endif /* _STLP_MEMBER_TEMPLATES */
   1.753 +  
   1.754 +  void _M_fill_insert(iterator __position, size_type __n, bool __x) {
   1.755 +    if (__n == 0) return;
   1.756 +    if (capacity() - size() >= __n) {
   1.757 +      __copy_backward(__position, end(), this->_M_finish + difference_type(__n), random_access_iterator_tag(), (difference_type*)0 );
   1.758 +      fill(__position, __position + difference_type(__n), __x);
   1.759 +      this->_M_finish += difference_type(__n);
   1.760 +    }
   1.761 +    else {
   1.762 +      size_type __len = size() + (max)(size(), __n);
   1.763 +      unsigned int* __q = this->_M_bit_alloc(__len);
   1.764 +      iterator __i = copy(begin(), __position, iterator(__q, 0));
   1.765 +      fill_n(__i, __n, __x);
   1.766 +      this->_M_finish = copy(__position, end(), __i + difference_type(__n));
   1.767 +      this->_M_deallocate();
   1.768 +      this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
   1.769 +      this->_M_start = iterator(__q, 0);
   1.770 +    }
   1.771 +  }
   1.772 +
   1.773 +  void insert(iterator __position, size_type __n, bool __x) {
   1.774 +    _M_fill_insert(__position, __n, __x);
   1.775 +  }
   1.776 +
   1.777 +  void pop_back() {
   1.778 +      --this->_M_finish; 
   1.779 +  }
   1.780 +  iterator erase(iterator __position) {
   1.781 +    if (__position + 1 != end())
   1.782 +      copy(__position + 1, end(), __position);
   1.783 +      --this->_M_finish;
   1.784 +    return __position;
   1.785 +  }
   1.786 +  iterator erase(iterator __first, iterator __last) {
   1.787 +    this->_M_finish = copy(__last, end(), __first);
   1.788 +    return __first;
   1.789 +  }
   1.790 +  void resize(size_type __new_size, bool __x = bool()) {
   1.791 +    if (__new_size < size()) 
   1.792 +      erase(begin() + difference_type(__new_size), end());
   1.793 +    else
   1.794 +      insert(end(), __new_size - size(), __x);
   1.795 +  }
   1.796 +  void flip() {
   1.797 +    for (unsigned int* __p = this->_M_start._M_p; __p != this->_M_end_of_storage._M_data; ++__p)
   1.798 +      *__p = ~*__p;
   1.799 +  }
   1.800 +
   1.801 +  void clear() { erase(begin(), end()); }
   1.802 +};
   1.803 +
   1.804 +# if defined  ( _STLP_NO_BOOL ) || defined (__HP_aCC) // fixed soon (03/17/2000)
   1.805 + 
   1.806 +#define _STLP_TEMPLATE_HEADER __BVEC_TMPL_HEADER
   1.807 +#define _STLP_TEMPLATE_CONTAINER __BVECTOR_QUALIFIED
   1.808 +#include <stl/_relops_cont.h>
   1.809 +#undef _STLP_TEMPLATE_CONTAINER
   1.810 +#undef _STLP_TEMPLATE_HEADER
   1.811 +  
   1.812 +# endif /* NO_BOOL */
   1.813 +  
   1.814 +#if !defined (_STLP_NO_BOOL)
   1.815 +// This typedef is non-standard.  It is provided for backward compatibility.
   1.816 +  typedef __WORKAROUND_DBG_RENAME(vector) <bool, allocator<bool> > bit_vector;
   1.817 +#endif
   1.818 +
   1.819 +_STLP_END_NAMESPACE
   1.820 +
   1.821 +#undef _Alloc
   1.822 +#undef _STLP_VECBOOL_TEMPLATE
   1.823 +#undef __BVECTOR
   1.824 +#undef __BVECTOR_QUALIFIED
   1.825 +#undef __BVEC_TMPL_HEADER
   1.826 +
   1.827 +# undef __WORD_BIT
   1.828 +
   1.829 +#endif /* _STLP_INTERNAL_BVECTOR_H */
   1.830 +
   1.831 +// Local Variables:
   1.832 +// mode:C++
   1.833 +// End:
   1.834 +