Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

stl_bvector.h

Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996-1999
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef __SGI_STL_INTERNAL_BVECTOR_H
00032 #define __SGI_STL_INTERNAL_BVECTOR_H
00033 
00034 namespace std
00035 { 
00036 
00037 static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));
00038 
00039 struct _Bit_reference {
00040   unsigned int* _M_p;
00041   unsigned int _M_mask;
00042   _Bit_reference(unsigned int* __x, unsigned int __y) 
00043     : _M_p(__x), _M_mask(__y) {}
00044 
00045 public:
00046   _Bit_reference() : _M_p(0), _M_mask(0) {}
00047   operator bool() const { return !(!(*_M_p & _M_mask)); }
00048   _Bit_reference& operator=(bool __x)
00049   {
00050     if (__x)  *_M_p |= _M_mask;
00051     else      *_M_p &= ~_M_mask;
00052     return *this;
00053   }
00054   _Bit_reference& operator=(const _Bit_reference& __x) 
00055     { return *this = bool(__x); }
00056   bool operator==(const _Bit_reference& __x) const
00057     { return bool(*this) == bool(__x); }
00058   bool operator<(const _Bit_reference& __x) const {
00059     return !bool(*this) && bool(__x);
00060   }
00061   void flip() { *_M_p ^= _M_mask; }
00062 };
00063 
00064 inline void swap(_Bit_reference __x, _Bit_reference __y)
00065 {
00066   bool __tmp = __x;
00067   __x = __y;
00068   __y = __tmp;
00069 }
00070 
00071 struct _Bit_iterator_base : public random_access_iterator<bool, ptrdiff_t> 
00072 {
00073   unsigned int* _M_p;
00074   unsigned int _M_offset;
00075 
00076   _Bit_iterator_base(unsigned int* __x, unsigned int __y)
00077     : _M_p(__x), _M_offset(__y) {}
00078 
00079   void _M_bump_up() {
00080     if (_M_offset++ == __WORD_BIT - 1) {
00081       _M_offset = 0;
00082       ++_M_p;
00083     }
00084   }
00085   void _M_bump_down() {
00086     if (_M_offset-- == 0) {
00087       _M_offset = __WORD_BIT - 1;
00088       --_M_p;
00089     }
00090   }
00091 
00092   void _M_incr(ptrdiff_t __i) {
00093     difference_type __n = __i + _M_offset;
00094     _M_p += __n / __WORD_BIT;
00095     __n = __n % __WORD_BIT;
00096     if (__n < 0) {
00097       _M_offset = (unsigned int) __n + __WORD_BIT;
00098       --_M_p;
00099     } else
00100       _M_offset = (unsigned int) __n;
00101   }
00102 
00103   bool operator==(const _Bit_iterator_base& __i) const {
00104     return _M_p == __i._M_p && _M_offset == __i._M_offset;
00105   }
00106   bool operator<(const _Bit_iterator_base& __i) const {
00107     return _M_p < __i._M_p || (_M_p == __i._M_p && _M_offset < __i._M_offset);
00108   }
00109   bool operator!=(const _Bit_iterator_base& __i) const {
00110     return !(*this == __i);
00111   }
00112   bool operator>(const _Bit_iterator_base& __i) const {
00113     return __i < *this;
00114   }
00115   bool operator<=(const _Bit_iterator_base& __i) const {
00116     return !(__i < *this); 
00117   }
00118   bool operator>=(const _Bit_iterator_base& __i) const {
00119     return !(*this < __i);
00120   }
00121 };
00122 
00123 inline ptrdiff_t
00124 operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
00125   return __WORD_BIT * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset;
00126 }
00127 
00128 
00129 struct _Bit_iterator : public _Bit_iterator_base
00130 {
00131   typedef _Bit_reference  reference;
00132   typedef _Bit_reference* pointer;
00133   typedef _Bit_iterator   iterator;
00134 
00135   _Bit_iterator() : _Bit_iterator_base(0, 0) {}
00136   _Bit_iterator(unsigned int* __x, unsigned int __y) 
00137     : _Bit_iterator_base(__x, __y) {}
00138 
00139   reference operator*() const { return reference(_M_p, 1U << _M_offset); }
00140   iterator& operator++() {
00141     _M_bump_up();
00142     return *this;
00143   }
00144   iterator operator++(int) {
00145     iterator __tmp = *this;
00146     _M_bump_up();
00147     return __tmp;
00148   }
00149   iterator& operator--() {
00150     _M_bump_down();
00151     return *this;
00152   }
00153   iterator operator--(int) {
00154     iterator __tmp = *this;
00155     _M_bump_down();
00156     return __tmp;
00157   }
00158   iterator& operator+=(difference_type __i) {
00159     _M_incr(__i);
00160     return *this;
00161   }
00162   iterator& operator-=(difference_type __i) {
00163     *this += -__i;
00164     return *this;
00165   }
00166   iterator operator+(difference_type __i) const {
00167     iterator __tmp = *this;
00168     return __tmp += __i;
00169   }
00170   iterator operator-(difference_type __i) const {
00171     iterator __tmp = *this;
00172     return __tmp -= __i;
00173   }
00174 
00175   reference operator[](difference_type __i) { return *(*this + __i); }
00176 };
00177 
00178 inline _Bit_iterator 
00179 operator+(ptrdiff_t __n, const _Bit_iterator& __x) { return __x + __n; }
00180 
00181 
00182 struct _Bit_const_iterator : public _Bit_iterator_base
00183 {
00184   typedef bool                 reference;
00185   typedef bool                 const_reference;
00186   typedef const bool*          pointer;
00187   typedef _Bit_const_iterator  const_iterator;
00188 
00189   _Bit_const_iterator() : _Bit_iterator_base(0, 0) {}
00190   _Bit_const_iterator(unsigned int* __x, unsigned int __y) 
00191     : _Bit_iterator_base(__x, __y) {}
00192   _Bit_const_iterator(const _Bit_iterator& __x) 
00193     : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
00194 
00195   const_reference operator*() const {
00196     return _Bit_reference(_M_p, 1U << _M_offset);
00197   }
00198   const_iterator& operator++() {
00199     _M_bump_up();
00200     return *this;
00201   }
00202   const_iterator operator++(int) {
00203     const_iterator __tmp = *this;
00204     _M_bump_up();
00205     return __tmp;
00206   }
00207   const_iterator& operator--() {
00208     _M_bump_down();
00209     return *this;
00210   }
00211   const_iterator operator--(int) {
00212     const_iterator __tmp = *this;
00213     _M_bump_down();
00214     return __tmp;
00215   }
00216   const_iterator& operator+=(difference_type __i) {
00217     _M_incr(__i);
00218     return *this;
00219   }
00220   const_iterator& operator-=(difference_type __i) {
00221     *this += -__i;
00222     return *this;
00223   }
00224   const_iterator operator+(difference_type __i) const {
00225     const_iterator __tmp = *this;
00226     return __tmp += __i;
00227   }
00228   const_iterator operator-(difference_type __i) const {
00229     const_iterator __tmp = *this;
00230     return __tmp -= __i;
00231   }
00232   const_reference operator[](difference_type __i) { 
00233     return *(*this + __i); 
00234   }
00235 };
00236 
00237 inline _Bit_const_iterator 
00238 operator+(ptrdiff_t __n, const _Bit_const_iterator& __x) { return __x + __n; }
00239 
00240 
00241 // Bit-vector base class, which encapsulates the difference between
00242 // old SGI-style allocators and standard-conforming allocators.
00243 
00244 // Base class for ordinary allocators.
00245 template <class _Allocator, bool __is_static>
00246 class _Bvector_alloc_base {
00247 public:
00248   typedef typename _Alloc_traits<bool, _Allocator>::allocator_type
00249           allocator_type;
00250   allocator_type get_allocator() const { return _M_data_allocator; }
00251 
00252   _Bvector_alloc_base(const allocator_type& __a)
00253     : _M_data_allocator(__a), _M_start(), _M_finish(), _M_end_of_storage(0) {}
00254 
00255 protected:
00256   unsigned int* _M_bit_alloc(size_t __n) 
00257     { return _M_data_allocator.allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
00258   void _M_deallocate() {
00259     if (_M_start._M_p)
00260       _M_data_allocator.deallocate(_M_start._M_p, 
00261                                    _M_end_of_storage - _M_start._M_p);
00262   }  
00263 
00264   typename _Alloc_traits<unsigned int, _Allocator>::allocator_type 
00265           _M_data_allocator;
00266   _Bit_iterator _M_start;
00267   _Bit_iterator _M_finish;
00268   unsigned int* _M_end_of_storage;
00269 };
00270 
00271 // Specialization for instanceless allocators.
00272 template <class _Allocator>
00273 class _Bvector_alloc_base<_Allocator, true> {
00274 public:
00275   typedef typename _Alloc_traits<bool, _Allocator>::allocator_type
00276           allocator_type;
00277   allocator_type get_allocator() const { return allocator_type(); }
00278 
00279   _Bvector_alloc_base(const allocator_type&)
00280     : _M_start(), _M_finish(), _M_end_of_storage(0) {}
00281 
00282 protected:
00283   typedef typename _Alloc_traits<unsigned int, _Allocator>::_Alloc_type
00284           _Alloc_type;
00285           
00286   unsigned int* _M_bit_alloc(size_t __n) 
00287     { return _Alloc_type::allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
00288   void _M_deallocate() {
00289     if (_M_start._M_p)
00290       _Alloc_type::deallocate(_M_start._M_p,
00291                               _M_end_of_storage - _M_start._M_p);
00292   }  
00293 
00294   _Bit_iterator _M_start;
00295   _Bit_iterator _M_finish;
00296   unsigned int* _M_end_of_storage;
00297 };  
00298 
00299 template <class _Alloc>
00300 class _Bvector_base
00301   : public _Bvector_alloc_base<_Alloc,
00302                                _Alloc_traits<bool, _Alloc>::_S_instanceless>
00303 {
00304   typedef _Bvector_alloc_base<_Alloc,
00305                               _Alloc_traits<bool, _Alloc>::_S_instanceless>
00306           _Base;
00307 public:
00308   typedef typename _Base::allocator_type allocator_type;
00309 
00310   _Bvector_base(const allocator_type& __a) : _Base(__a) {}
00311   ~_Bvector_base() { _Base::_M_deallocate(); }
00312 };
00313 
00314 } // namespace std
00315 
00316 // Declare a partial specialization of vector<T, Alloc>.
00317 #include <bits/stl_vector.h>
00318 namespace std
00319 {
00320 
00321 template <typename _Alloc> 
00322   class vector<bool, _Alloc> : public _Bvector_base<_Alloc> 
00323   {
00324   public:
00325     typedef bool value_type;
00326     typedef size_t size_type;
00327     typedef ptrdiff_t difference_type; 
00328     typedef _Bit_reference reference;
00329     typedef bool const_reference;
00330     typedef _Bit_reference* pointer;
00331     typedef const bool* const_pointer;
00332   
00333     typedef _Bit_iterator                iterator;
00334     typedef _Bit_const_iterator          const_iterator;
00335   
00336     typedef reverse_iterator<const_iterator> const_reverse_iterator;
00337     typedef reverse_iterator<iterator> reverse_iterator;
00338   
00339     typedef typename _Bvector_base<_Alloc>::allocator_type allocator_type;
00340     allocator_type get_allocator() const {
00341       return _Bvector_base<_Alloc>::get_allocator();
00342     }
00343   
00344   protected:
00345     using _Bvector_base<_Alloc>::_M_bit_alloc;
00346     using _Bvector_base<_Alloc>::_M_deallocate;
00347     using _Bvector_base<_Alloc>::_M_start;
00348     using _Bvector_base<_Alloc>::_M_finish;
00349     using _Bvector_base<_Alloc>::_M_end_of_storage;
00350   
00351   protected:
00352     void _M_initialize(size_type __n) {
00353       unsigned int* __q = _M_bit_alloc(__n);
00354       _M_end_of_storage = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
00355       _M_start = iterator(__q, 0);
00356       _M_finish = _M_start + difference_type(__n);
00357     }
00358     void _M_insert_aux(iterator __position, bool __x) {
00359       if (_M_finish._M_p != _M_end_of_storage) {
00360         copy_backward(__position, _M_finish, _M_finish + 1);
00361         *__position = __x;
00362         ++_M_finish;
00363       }
00364       else {
00365         size_type __len = size() ? 2 * size() : __WORD_BIT;
00366         unsigned int* __q = _M_bit_alloc(__len);
00367         iterator __i = copy(begin(), __position, iterator(__q, 0));
00368         *__i++ = __x;
00369         _M_finish = copy(__position, end(), __i);
00370         _M_deallocate();
00371         _M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
00372         _M_start = iterator(__q, 0);
00373       }
00374     }
00375   
00376     template <class _InputIterator>
00377     void _M_initialize_range(_InputIterator __first, _InputIterator __last,
00378                              input_iterator_tag) {
00379       _M_start = iterator();
00380       _M_finish = iterator();
00381       _M_end_of_storage = 0;
00382       for ( ; __first != __last; ++__first) 
00383         push_back(*__first);
00384     }
00385   
00386     template <class _ForwardIterator>
00387     void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
00388                              forward_iterator_tag) {
00389       size_type __n = 0;
00390       distance(__first, __last, __n);
00391       _M_initialize(__n);
00392       copy(__first, __last, _M_start);
00393     }
00394   
00395     template <class _InputIterator>
00396     void _M_insert_range(iterator __pos,
00397                          _InputIterator __first, _InputIterator __last,
00398                          input_iterator_tag) {
00399       for ( ; __first != __last; ++__first) {
00400         __pos = insert(__pos, *__first);
00401         ++__pos;
00402       }
00403     }
00404   
00405     template <class _ForwardIterator>
00406     void _M_insert_range(iterator __position,
00407                          _ForwardIterator __first, _ForwardIterator __last,
00408                          forward_iterator_tag) {
00409       if (__first != __last) {
00410         size_type __n = 0;
00411         distance(__first, __last, __n);
00412         if (capacity() - size() >= __n) {
00413           copy_backward(__position, end(), _M_finish + difference_type(__n));
00414           copy(__first, __last, __position);
00415           _M_finish += difference_type(__n);
00416         }
00417         else {
00418           size_type __len = size() + max(size(), __n);
00419           unsigned int* __q = _M_bit_alloc(__len);
00420           iterator __i = copy(begin(), __position, iterator(__q, 0));
00421           __i = copy(__first, __last, __i);
00422           _M_finish = copy(__position, end(), __i);
00423           _M_deallocate();
00424           _M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
00425           _M_start = iterator(__q, 0);
00426         }
00427       }
00428     }      
00429   
00430   public:
00431     iterator begin() { return _M_start; }
00432     const_iterator begin() const { return _M_start; }
00433     iterator end() { return _M_finish; }
00434     const_iterator end() const { return _M_finish; }
00435   
00436     reverse_iterator rbegin() { return reverse_iterator(end()); }
00437     const_reverse_iterator rbegin() const { 
00438       return const_reverse_iterator(end()); 
00439     }
00440     reverse_iterator rend() { return reverse_iterator(begin()); }
00441     const_reverse_iterator rend() const { 
00442       return const_reverse_iterator(begin()); 
00443     }
00444   
00445     size_type size() const { return size_type(end() - begin()); }
00446     size_type max_size() const { return size_type(-1); }
00447     size_type capacity() const {
00448       return size_type(const_iterator(_M_end_of_storage, 0) - begin());
00449     }
00450     bool empty() const { return begin() == end(); }
00451   
00452     reference operator[](size_type __n)
00453       { return *(begin() + difference_type(__n)); }
00454     const_reference operator[](size_type __n) const
00455       { return *(begin() + difference_type(__n)); }
00456   
00457     void _M_range_check(size_type __n) const {
00458       if (__n >= this->size())
00459         __throw_range_error("vector<bool>");
00460     }
00461   
00462     reference at(size_type __n)
00463       { _M_range_check(__n); return (*this)[__n]; }
00464     const_reference at(size_type __n) const
00465       { _M_range_check(__n); return (*this)[__n]; }
00466   
00467     explicit vector(const allocator_type& __a = allocator_type())
00468       : _Bvector_base<_Alloc>(__a) {}
00469   
00470     vector(size_type __n, bool __value,
00471               const allocator_type& __a = allocator_type())
00472       : _Bvector_base<_Alloc>(__a)
00473     {
00474       _M_initialize(__n);
00475       fill(_M_start._M_p, _M_end_of_storage, __value ? ~0 : 0);
00476     }
00477   
00478     explicit vector(size_type __n)
00479       : _Bvector_base<_Alloc>(allocator_type())
00480     {
00481       _M_initialize(__n);
00482       fill(_M_start._M_p, _M_end_of_storage, 0);
00483     }
00484   
00485     vector(const vector& __x) : _Bvector_base<_Alloc>(__x.get_allocator()) {
00486       _M_initialize(__x.size());
00487       copy(__x.begin(), __x.end(), _M_start);
00488     }
00489   
00490     // Check whether it's an integral type.  If so, it's not an iterator.
00491   
00492     template <class _Integer>
00493     void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
00494       _M_initialize(__n);
00495       fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
00496     }
00497   
00498     template <class _InputIterator>
00499     void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
00500                                 __false_type) {
00501       _M_initialize_range(__first, __last, __iterator_category(__first));
00502     }
00503   
00504     template <class _InputIterator>
00505     vector(_InputIterator __first, _InputIterator __last,
00506              const allocator_type& __a = allocator_type())
00507       : _Bvector_base<_Alloc>(__a)
00508     {
00509       typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
00510       _M_initialize_dispatch(__first, __last, _Integral());
00511     }
00512       
00513     ~vector() { }
00514   
00515     vector& operator=(const vector& __x) {
00516       if (&__x == this) return *this;
00517       if (__x.size() > capacity()) {
00518         _M_deallocate();
00519         _M_initialize(__x.size());
00520       }
00521       copy(__x.begin(), __x.end(), begin());
00522       _M_finish = begin() + difference_type(__x.size());
00523       return *this;
00524     }
00525   
00526     // assign(), a generalized assignment member function.  Two
00527     // versions: one that takes a count, and one that takes a range.
00528     // The range version is a member template, so we dispatch on whether
00529     // or not the type is an integer.
00530   
00531     void _M_fill_assign(size_t __n, bool __x) {
00532       if (__n > size()) {
00533         fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
00534         insert(end(), __n - size(), __x);
00535       }
00536       else {
00537         erase(begin() + __n, end());
00538         fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
00539       }
00540     }
00541   
00542     void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
00543   
00544     template <class _InputIterator>
00545     void assign(_InputIterator __first, _InputIterator __last) {
00546       typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
00547       _M_assign_dispatch(__first, __last, _Integral());
00548     }
00549   
00550     template <class _Integer>
00551     void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
00552       { _M_fill_assign((size_t) __n, (bool) __val); }
00553   
00554     template <class _InputIter>
00555     void _M_assign_dispatch(_InputIter __first, _InputIter __last, __false_type)
00556       { _M_assign_aux(__first, __last, __iterator_category(__first)); }
00557   
00558     template <class _InputIterator>
00559     void _M_assign_aux(_InputIterator __first, _InputIterator __last,
00560                        input_iterator_tag) {
00561       iterator __cur = begin();
00562       for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
00563         *__cur = *__first;
00564       if (__first == __last)
00565         erase(__cur, end());
00566       else
00567         insert(end(), __first, __last);
00568     }
00569   
00570     template <class _ForwardIterator>
00571     void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
00572                        forward_iterator_tag) {
00573       size_type __len = 0;
00574       distance(__first, __last, __len);
00575       if (__len < size())
00576         erase(copy(__first, __last, begin()), end());
00577       else {
00578         _ForwardIterator __mid = __first;
00579         advance(__mid, size());
00580         copy(__first, __mid, begin());
00581         insert(end(), __mid, __last);
00582       }
00583     }    
00584   
00585     void reserve(size_type __n) {
00586       if (capacity() < __n) {
00587         unsigned int* __q = _M_bit_alloc(__n);
00588         _M_finish = copy(begin(), end(), iterator(__q, 0));
00589         _M_deallocate();
00590         _M_start = iterator(__q, 0);
00591         _M_end_of_storage = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
00592       }
00593     }
00594   
00595     reference front() { return *begin(); }
00596     const_reference front() const { return *begin(); }
00597     reference back() { return *(end() - 1); }
00598     const_reference back() const { return *(end() - 1); }
00599     void push_back(bool __x) {
00600       if (_M_finish._M_p != _M_end_of_storage)
00601         *_M_finish++ = __x;
00602       else
00603         _M_insert_aux(end(), __x);
00604     }
00605     void swap(vector<bool, _Alloc>& __x) {
00606       std::swap(_M_start, __x._M_start);
00607       std::swap(_M_finish, __x._M_finish);
00608       std::swap(_M_end_of_storage, __x._M_end_of_storage);
00609     }
00610     iterator insert(iterator __position, bool __x = bool()) {
00611       difference_type __n = __position - begin();
00612       if (_M_finish._M_p != _M_end_of_storage && __position == end())
00613         *_M_finish++ = __x;
00614       else
00615         _M_insert_aux(__position, __x);
00616       return begin() + __n;
00617     }
00618   
00619     // Check whether it's an integral type.  If so, it's not an iterator.
00620   
00621     template <class _Integer>
00622     void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
00623                             __true_type) {
00624       _M_fill_insert(__pos, __n, __x);
00625     }
00626   
00627     template <class _InputIterator>
00628     void _M_insert_dispatch(iterator __pos,
00629                             _InputIterator __first, _InputIterator __last,
00630                             __false_type) {
00631       _M_insert_range(__pos, __first, __last, __iterator_category(__first));
00632     }
00633   
00634     template <class _InputIterator>
00635     void insert(iterator __position,
00636                 _InputIterator __first, _InputIterator __last) {
00637       typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
00638       _M_insert_dispatch(__position, __first, __last, _Integral());
00639     }
00640   
00641     void _M_fill_insert(iterator __position, size_type __n, bool __x) {
00642       if (__n == 0) return;
00643       if (capacity() - size() >= __n) {
00644         copy_backward(__position, end(), _M_finish + difference_type(__n));
00645         fill(__position, __position + difference_type(__n), __x);
00646         _M_finish += difference_type(__n);
00647       }
00648       else {
00649         size_type __len = size() + max(size(), __n);
00650         unsigned int* __q = _M_bit_alloc(__len);
00651         iterator __i = copy(begin(), __position, iterator(__q, 0));
00652         fill_n(__i, __n, __x);
00653         _M_finish = copy(__position, end(), __i + difference_type(__n));
00654         _M_deallocate();
00655         _M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
00656         _M_start = iterator(__q, 0);
00657       }
00658     }
00659   
00660     void insert(iterator __position, size_type __n, bool __x) {
00661       _M_fill_insert(__position, __n, __x);
00662     }
00663   
00664     void pop_back() { --_M_finish; }
00665     iterator erase(iterator __position) {
00666       if (__position + 1 != end())
00667         copy(__position + 1, end(), __position);
00668         --_M_finish;
00669       return __position;
00670     }
00671     iterator erase(iterator __first, iterator __last) {
00672       _M_finish = copy(__last, end(), __first);
00673       return __first;
00674     }
00675     void resize(size_type __new_size, bool __x = bool()) {
00676       if (__new_size < size()) 
00677         erase(begin() + difference_type(__new_size), end());
00678       else
00679         insert(end(), __new_size - size(), __x);
00680     }
00681     void flip() {
00682       for (unsigned int* __p = _M_start._M_p; __p != _M_end_of_storage; ++__p)
00683         *__p = ~*__p;
00684     }
00685   
00686     void clear() { erase(begin(), end()); }
00687   };
00688 
00689 // This typedef is non-standard.  It is provided for backward compatibility.
00690 typedef vector<bool, alloc> bit_vector;
00691 
00692 } // namespace std 
00693 
00694 #endif /* __SGI_STL_INTERNAL_BVECTOR_H */
00695 
00696 // Local Variables:
00697 // mode:C++
00698 // End:

Generated at Tue May 1 16:28:39 2001 for libstdc++-v3 by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001