OSDN Git Service

34b1a87ad5d3d8a97e209597456a3b229eea75f6
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / stl_bvector.h
1 // bit_vector and vector<bool> specialization -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction.  Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License.  This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
29
30 /*
31  *
32  * Copyright (c) 1994
33  * Hewlett-Packard Company
34  *
35  * Permission to use, copy, modify, distribute and sell this software
36  * and its documentation for any purpose is hereby granted without fee,
37  * provided that the above copyright notice appear in all copies and
38  * that both that copyright notice and this permission notice appear
39  * in supporting documentation.  Hewlett-Packard Company makes no
40  * representations about the suitability of this software for any
41  * purpose.  It is provided "as is" without express or implied warranty.
42  *
43  *
44  * Copyright (c) 1996-1999
45  * Silicon Graphics Computer Systems, Inc.
46  *
47  * Permission to use, copy, modify, distribute and sell this software
48  * and its documentation for any purpose is hereby granted without fee,
49  * provided that the above copyright notice appear in all copies and
50  * that both that copyright notice and this permission notice appear
51  * in supporting documentation.  Silicon Graphics makes no
52  * representations about the suitability of this software for any
53  * purpose.  It is provided "as is" without express or implied warranty.
54  */
55
56 /** @file stl_bvector.h
57  *  This is an internal header file, included by other library headers.
58  *  You should not attempt to use it directly.
59  */
60
61 #ifndef _BVECTOR_H
62 #define _BVECTOR_H 1
63
64 namespace __gnu_norm
65
66   typedef unsigned long _Bit_type;
67   enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
68
69 struct _Bit_reference {
70
71   _Bit_type * _M_p;
72   _Bit_type _M_mask;
73   _Bit_reference(_Bit_type * __x, _Bit_type __y) 
74     : _M_p(__x), _M_mask(__y) {}
75
76 public:
77   _Bit_reference() : _M_p(0), _M_mask(0) {}
78   operator bool() const { return !!(*_M_p & _M_mask); }
79   _Bit_reference& operator=(bool __x)
80   {
81     if (__x)  *_M_p |= _M_mask;
82     else      *_M_p &= ~_M_mask;
83     return *this;
84   }
85   _Bit_reference& operator=(const _Bit_reference& __x) 
86     { return *this = bool(__x); }
87   bool operator==(const _Bit_reference& __x) const
88     { return bool(*this) == bool(__x); }
89   bool operator<(const _Bit_reference& __x) const
90     { return !bool(*this) && bool(__x); }
91   void flip() { *_M_p ^= _M_mask; }
92 };
93
94 struct _Bit_iterator_base : public iterator<random_access_iterator_tag, bool>
95 {
96   _Bit_type * _M_p;
97   unsigned int _M_offset;
98
99   _Bit_iterator_base(_Bit_type * __x, unsigned int __y)
100     : _M_p(__x), _M_offset(__y) {}
101
102   void _M_bump_up() {
103     if (_M_offset++ == _S_word_bit - 1) {
104       _M_offset = 0;
105       ++_M_p;
106     }
107   }
108   void _M_bump_down() {
109     if (_M_offset-- == 0) {
110       _M_offset = _S_word_bit - 1;
111       --_M_p;
112     }
113   }
114
115   void _M_incr(ptrdiff_t __i) {
116     difference_type __n = __i + _M_offset;
117     _M_p += __n / _S_word_bit;
118     __n = __n % _S_word_bit;
119     if (__n < 0) {
120       _M_offset = (unsigned int) __n + _S_word_bit;
121       --_M_p;
122     } else
123       _M_offset = (unsigned int) __n;
124   }
125
126   bool operator==(const _Bit_iterator_base& __i) const {
127     return _M_p == __i._M_p && _M_offset == __i._M_offset;
128   }
129   bool operator<(const _Bit_iterator_base& __i) const {
130     return _M_p < __i._M_p || (_M_p == __i._M_p && _M_offset < __i._M_offset);
131   }
132   bool operator!=(const _Bit_iterator_base& __i) const {
133     return !(*this == __i);
134   }
135   bool operator>(const _Bit_iterator_base& __i) const {
136     return __i < *this;
137   }
138   bool operator<=(const _Bit_iterator_base& __i) const {
139     return !(__i < *this); 
140   }
141   bool operator>=(const _Bit_iterator_base& __i) const {
142     return !(*this < __i);
143   }
144 };
145
146 inline ptrdiff_t
147 operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
148   return _S_word_bit * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset;
149 }
150
151
152 struct _Bit_iterator : public _Bit_iterator_base
153 {
154   typedef _Bit_reference  reference;
155   typedef _Bit_reference* pointer;
156   typedef _Bit_iterator   iterator;
157
158   _Bit_iterator() : _Bit_iterator_base(0, 0) {}
159   _Bit_iterator(_Bit_type * __x, unsigned int __y) 
160     : _Bit_iterator_base(__x, __y) {}
161
162   reference operator*() const { return reference(_M_p, 1UL << _M_offset); }
163   iterator& operator++() {
164     _M_bump_up();
165     return *this;
166   }
167   iterator operator++(int) {
168     iterator __tmp = *this;
169     _M_bump_up();
170     return __tmp;
171   }
172   iterator& operator--() {
173     _M_bump_down();
174     return *this;
175   }
176   iterator operator--(int) {
177     iterator __tmp = *this;
178     _M_bump_down();
179     return __tmp;
180   }
181   iterator& operator+=(difference_type __i) {
182     _M_incr(__i);
183     return *this;
184   }
185   iterator& operator-=(difference_type __i) {
186     *this += -__i;
187     return *this;
188   }
189   iterator operator+(difference_type __i) const {
190     iterator __tmp = *this;
191     return __tmp += __i;
192   }
193   iterator operator-(difference_type __i) const {
194     iterator __tmp = *this;
195     return __tmp -= __i;
196   }
197
198   reference operator[](difference_type __i) { return *(*this + __i); }
199 };
200
201 inline _Bit_iterator 
202 operator+(ptrdiff_t __n, const _Bit_iterator& __x) { return __x + __n; }
203
204
205 struct _Bit_const_iterator : public _Bit_iterator_base
206 {
207   typedef bool                 reference;
208   typedef bool                 const_reference;
209   typedef const bool*          pointer;
210   typedef _Bit_const_iterator  const_iterator;
211
212   _Bit_const_iterator() : _Bit_iterator_base(0, 0) {}
213   _Bit_const_iterator(_Bit_type * __x, unsigned int __y) 
214     : _Bit_iterator_base(__x, __y) {}
215   _Bit_const_iterator(const _Bit_iterator& __x) 
216     : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
217
218   const_reference operator*() const {
219     return _Bit_reference(_M_p, 1UL << _M_offset);
220   }
221   const_iterator& operator++() {
222     _M_bump_up();
223     return *this;
224   }
225   const_iterator operator++(int) {
226     const_iterator __tmp = *this;
227     _M_bump_up();
228     return __tmp;
229   }
230   const_iterator& operator--() {
231     _M_bump_down();
232     return *this;
233   }
234   const_iterator operator--(int) {
235     const_iterator __tmp = *this;
236     _M_bump_down();
237     return __tmp;
238   }
239   const_iterator& operator+=(difference_type __i) {
240     _M_incr(__i);
241     return *this;
242   }
243   const_iterator& operator-=(difference_type __i) {
244     *this += -__i;
245     return *this;
246   }
247   const_iterator operator+(difference_type __i) const {
248     const_iterator __tmp = *this;
249     return __tmp += __i;
250   }
251   const_iterator operator-(difference_type __i) const {
252     const_iterator __tmp = *this;
253     return __tmp -= __i;
254   }
255   const_reference operator[](difference_type __i) { 
256     return *(*this + __i); 
257   }
258 };
259
260 inline _Bit_const_iterator 
261 operator+(ptrdiff_t __n, const _Bit_const_iterator& __x) { return __x + __n; }
262
263
264 template <class _Alloc>
265 class _Bvector_base
266   : public _Alloc::template rebind<_Bit_type>::other
267 {
268   typedef typename _Alloc::template rebind<_Bit_type>::other _Bit_alloc_type;
269 public:
270   typedef _Alloc allocator_type;
271   allocator_type get_allocator() const {
272     return *static_cast<const _Bit_alloc_type*>(this);
273   }
274
275   _Bvector_base(const allocator_type& __a)
276     : _Bit_alloc_type(__a), _M_start(), _M_finish(), _M_end_of_storage(0) { }
277   ~_Bvector_base() { this->_M_deallocate(); }
278
279 protected:
280   _Bit_type* _M_bit_alloc(size_t __n) {
281     return _Bit_alloc_type::allocate((__n + _S_word_bit - 1)/_S_word_bit);
282   }
283   void _M_deallocate() {
284     if (_M_start._M_p)
285       _Bit_alloc_type::deallocate(_M_start._M_p, _M_end_of_storage - _M_start._M_p);
286   }  
287
288   _Bit_iterator _M_start;
289   _Bit_iterator _M_finish;
290   _Bit_type * _M_end_of_storage;
291 };
292
293 } // namespace __gnu_norm
294
295 // Declare a partial specialization of vector<T, Alloc>.
296 #include <bits/stl_vector.h>
297 namespace __gnu_norm
298 {
299
300   /**
301    *  @brief  A specialization of vector for booleans which offers fixed time
302    *  access to individual elements in any order.
303    *
304    *  Note that vector<bool> does not actually meet the requirements for being
305    *  a container.  This is because the reference and pointer types are not
306    *  really references and pointers to bool.  See DR96 for details.  @see
307    *  vector for function documentation.
308    *
309    *  @ingroup Containers
310    *  @ingroup Sequences
311    *
312    *  In some terminology a %vector can be described as a dynamic C-style array,
313    *  it offers fast and efficient access to individual elements in any order
314    *  and saves the user from worrying about memory and size allocation.
315    *  Subscripting ( @c [] ) access is also provided as with C-style arrays.
316   */
317 template <typename _Alloc> 
318   class vector<bool, _Alloc> : public _Bvector_base<_Alloc> 
319   {
320   public:
321     typedef bool value_type;
322     typedef size_t size_type;
323     typedef ptrdiff_t difference_type; 
324     typedef _Bit_reference reference;
325     typedef bool const_reference;
326     typedef _Bit_reference* pointer;
327     typedef const bool* const_pointer;
328   
329     typedef _Bit_iterator                iterator;
330     typedef _Bit_const_iterator          const_iterator;
331   
332     typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
333     typedef std::reverse_iterator<iterator> reverse_iterator;
334   
335     typedef typename _Bvector_base<_Alloc>::allocator_type allocator_type;
336     allocator_type get_allocator() const {
337       return _Bvector_base<_Alloc>::get_allocator();
338     }
339   
340   protected:
341     using _Bvector_base<_Alloc>::_M_bit_alloc;
342     using _Bvector_base<_Alloc>::_M_deallocate;
343     using _Bvector_base<_Alloc>::_M_start;
344     using _Bvector_base<_Alloc>::_M_finish;
345     using _Bvector_base<_Alloc>::_M_end_of_storage;
346   
347   protected:
348     void _M_initialize(size_type __n) {
349       _Bit_type * __q = this->_M_bit_alloc(__n);
350       this->_M_end_of_storage = __q + (__n + _S_word_bit - 1)/_S_word_bit;
351       this->_M_start = iterator(__q, 0);
352       this->_M_finish = this->_M_start + difference_type(__n);
353     }
354     void _M_insert_aux(iterator __position, bool __x) {
355       if (this->_M_finish._M_p != this->_M_end_of_storage) {
356         std::copy_backward(__position, this->_M_finish, this->_M_finish + 1);
357         *__position = __x;
358         ++this->_M_finish;
359       }
360       else {
361         size_type __len = size() 
362                           ? 2 * size() : static_cast<size_type>(_S_word_bit);
363         _Bit_type * __q = this->_M_bit_alloc(__len);
364         iterator __i = std::copy(begin(), __position, iterator(__q, 0));
365         *__i++ = __x;
366         this->_M_finish = std::copy(__position, end(), __i);
367         this->_M_deallocate();
368         this->_M_end_of_storage = __q + (__len + _S_word_bit - 1)/_S_word_bit;
369         this->_M_start = iterator(__q, 0);
370       }
371     }
372   
373     template <class _InputIterator>
374     void _M_initialize_range(_InputIterator __first, _InputIterator __last,
375                              input_iterator_tag) {
376       this->_M_start = iterator();
377       this->_M_finish = iterator();
378       this->_M_end_of_storage = 0;
379       for ( ; __first != __last; ++__first) 
380         push_back(*__first);
381     }
382   
383     template <class _ForwardIterator>
384     void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
385                              forward_iterator_tag) {
386       size_type __n = std::distance(__first, __last);
387       _M_initialize(__n);
388       std::copy(__first, __last, this->_M_start);
389     }
390   
391     template <class _InputIterator>
392     void _M_insert_range(iterator __pos,
393                          _InputIterator __first, _InputIterator __last,
394                          input_iterator_tag) {
395       for ( ; __first != __last; ++__first) {
396         __pos = insert(__pos, *__first);
397         ++__pos;
398       }
399     }
400   
401     template <class _ForwardIterator>
402     void _M_insert_range(iterator __position,
403                          _ForwardIterator __first, _ForwardIterator __last,
404                          forward_iterator_tag) {
405       if (__first != __last) {
406         size_type __n = std::distance(__first, __last);
407         if (capacity() - size() >= __n) {
408           std::copy_backward(__position, end(),
409                              this->_M_finish + difference_type(__n));
410           std::copy(__first, __last, __position);
411           this->_M_finish += difference_type(__n);
412         }
413         else {
414           size_type __len = size() + std::max(size(), __n);
415           _Bit_type * __q = this->_M_bit_alloc(__len);
416           iterator __i = std::copy(begin(), __position, iterator(__q, 0));
417           __i = std::copy(__first, __last, __i);
418           this->_M_finish = std::copy(__position, end(), __i);
419           this->_M_deallocate();
420           this->_M_end_of_storage
421             = __q + (__len + _S_word_bit - 1)/_S_word_bit;
422           this->_M_start = iterator(__q, 0);
423         }
424       }
425     }      
426   
427   public:
428     iterator begin() { return this->_M_start; }
429     const_iterator begin() const { return this->_M_start; }
430     iterator end() { return this->_M_finish; }
431     const_iterator end() const { return this->_M_finish; }
432   
433     reverse_iterator rbegin() { return reverse_iterator(end()); }
434     const_reverse_iterator rbegin() const { 
435       return const_reverse_iterator(end()); 
436     }
437     reverse_iterator rend() { return reverse_iterator(begin()); }
438     const_reverse_iterator rend() const { 
439       return const_reverse_iterator(begin()); 
440     }
441   
442     size_type size() const { return size_type(end() - begin()); }
443     size_type max_size() const { return size_type(-1); }
444     size_type capacity() const {
445       return size_type(const_iterator(this->_M_end_of_storage, 0) - begin());
446     }
447     bool empty() const { return begin() == end(); }
448   
449     reference operator[](size_type __n)
450       { return *(begin() + difference_type(__n)); }
451     const_reference operator[](size_type __n) const
452       { return *(begin() + difference_type(__n)); }
453   
454     void _M_range_check(size_type __n) const {
455       if (__n >= this->size())
456         __throw_out_of_range(__N("vector<bool>::_M_range_check"));
457     }
458   
459     reference at(size_type __n)
460       { _M_range_check(__n); return (*this)[__n]; }
461     const_reference at(size_type __n) const
462       { _M_range_check(__n); return (*this)[__n]; }
463   
464     explicit vector(const allocator_type& __a = allocator_type())
465       : _Bvector_base<_Alloc>(__a) {}
466   
467     vector(size_type __n, bool __value,
468               const allocator_type& __a = allocator_type())
469       : _Bvector_base<_Alloc>(__a)
470     {
471       _M_initialize(__n);
472       std::fill(this->_M_start._M_p, this->_M_end_of_storage, __value ? ~0 : 0);
473     }
474   
475     explicit vector(size_type __n)
476       : _Bvector_base<_Alloc>(allocator_type())
477     {
478       _M_initialize(__n);
479       std::fill(this->_M_start._M_p, this->_M_end_of_storage, 0);
480     }
481   
482     vector(const vector& __x) : _Bvector_base<_Alloc>(__x.get_allocator()) {
483       _M_initialize(__x.size());
484       std::copy(__x.begin(), __x.end(), this->_M_start);
485     }
486   
487     // Check whether it's an integral type.  If so, it's not an iterator.
488   
489     template <class _Integer>
490     void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
491       _M_initialize(__n);
492       std::fill(this->_M_start._M_p, this->_M_end_of_storage, __x ? ~0 : 0);
493     }
494   
495     template <class _InputIterator>
496     void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
497                                 __false_type) {
498       _M_initialize_range(__first, __last, std::__iterator_category(__first));
499     }
500   
501     template <class _InputIterator>
502     vector(_InputIterator __first, _InputIterator __last,
503              const allocator_type& __a = allocator_type())
504       : _Bvector_base<_Alloc>(__a)
505     {
506       typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
507       _M_initialize_dispatch(__first, __last, _Integral());
508     }
509       
510     ~vector() { }
511   
512     vector& operator=(const vector& __x) {
513       if (&__x == this) return *this;
514       if (__x.size() > capacity()) {
515         this->_M_deallocate();
516         _M_initialize(__x.size());
517       }
518       std::copy(__x.begin(), __x.end(), begin());
519       this->_M_finish = begin() + difference_type(__x.size());
520       return *this;
521     }
522   
523     // assign(), a generalized assignment member function.  Two
524     // versions: one that takes a count, and one that takes a range.
525     // The range version is a member template, so we dispatch on whether
526     // or not the type is an integer.
527   
528     void _M_fill_assign(size_t __n, bool __x) {
529       if (__n > size()) {
530         std::fill(this->_M_start._M_p, this->_M_end_of_storage, __x ? ~0 : 0);
531         insert(end(), __n - size(), __x);
532       }
533       else {
534         erase(begin() + __n, end());
535         std::fill(this->_M_start._M_p, this->_M_end_of_storage, __x ? ~0 : 0);
536       }
537     }
538   
539     void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
540   
541     template <class _InputIterator>
542     void assign(_InputIterator __first, _InputIterator __last) {
543       typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
544       _M_assign_dispatch(__first, __last, _Integral());
545     }
546   
547     template <class _Integer>
548     void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
549       { _M_fill_assign((size_t) __n, (bool) __val); }
550   
551     template <class _InputIterator>
552     void _M_assign_dispatch(_InputIterator __first, _InputIterator __last, __false_type)
553       { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
554   
555     template <class _InputIterator>
556     void _M_assign_aux(_InputIterator __first, _InputIterator __last,
557                        input_iterator_tag) {
558       iterator __cur = begin();
559       for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
560         *__cur = *__first;
561       if (__first == __last)
562         erase(__cur, end());
563       else
564         insert(end(), __first, __last);
565     }
566   
567     template <class _ForwardIterator>
568     void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
569                        forward_iterator_tag) {
570       size_type __len = std::distance(__first, __last);
571       if (__len < size())
572         erase(std::copy(__first, __last, begin()), end());
573       else {
574         _ForwardIterator __mid = __first;
575         std::advance(__mid, size());
576         std::copy(__first, __mid, begin());
577         insert(end(), __mid, __last);
578       }
579     }    
580   
581     void reserve(size_type __n) {
582       if (__n > this->max_size())
583         __throw_length_error(__N("vector::reserve"));
584       if (this->capacity() < __n) {
585         _Bit_type * __q = this->_M_bit_alloc(__n);
586         this->_M_finish = std::copy(begin(), end(), iterator(__q, 0));
587         this->_M_deallocate();
588         this->_M_start = iterator(__q, 0);
589         this->_M_end_of_storage = __q + (__n + _S_word_bit - 1)/_S_word_bit;
590       }
591     }
592   
593     reference front() { return *begin(); }
594     const_reference front() const { return *begin(); }
595     reference back() { return *(end() - 1); }
596     const_reference back() const { return *(end() - 1); }
597     void push_back(bool __x) {
598       if (this->_M_finish._M_p != this->_M_end_of_storage)
599         *this->_M_finish++ = __x;
600       else
601         _M_insert_aux(end(), __x);
602     }
603     void swap(vector<bool, _Alloc>& __x) {
604       std::swap(this->_M_start, __x._M_start);
605       std::swap(this->_M_finish, __x._M_finish);
606       std::swap(this->_M_end_of_storage, __x._M_end_of_storage);
607     }
608
609     // [23.2.5]/1, third-to-last entry in synopsis listing
610     static void swap(reference __x, reference __y) {
611       bool __tmp = __x;
612       __x = __y;
613       __y = __tmp;
614     }
615
616     iterator insert(iterator __position, bool __x = bool()) {
617       difference_type __n = __position - begin();
618       if (this->_M_finish._M_p != this->_M_end_of_storage
619           && __position == end())
620         *this->_M_finish++ = __x;
621       else
622         _M_insert_aux(__position, __x);
623       return begin() + __n;
624     }
625   
626     // Check whether it's an integral type.  If so, it's not an iterator.
627   
628     template <class _Integer>
629     void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
630                             __true_type) {
631       _M_fill_insert(__pos, __n, __x);
632     }
633   
634     template <class _InputIterator>
635     void _M_insert_dispatch(iterator __pos,
636                             _InputIterator __first, _InputIterator __last,
637                             __false_type) {
638       _M_insert_range(__pos, __first, __last, std::__iterator_category(__first));
639     }
640   
641     template <class _InputIterator>
642     void insert(iterator __position,
643                 _InputIterator __first, _InputIterator __last) {
644       typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
645       _M_insert_dispatch(__position, __first, __last, _Integral());
646     }
647   
648     void _M_fill_insert(iterator __position, size_type __n, bool __x) {
649       if (__n == 0) return;
650       if (capacity() - size() >= __n) {
651         std::copy_backward(__position, end(),
652                            this->_M_finish + difference_type(__n));
653         std::fill(__position, __position + difference_type(__n), __x);
654         this->_M_finish += difference_type(__n);
655       }
656       else {
657         size_type __len = size() + std::max(size(), __n);
658         _Bit_type * __q = this->_M_bit_alloc(__len);
659         iterator __i = std::copy(begin(), __position, iterator(__q, 0));
660         std::fill_n(__i, __n, __x);
661         this->_M_finish = std::copy(__position, end(), __i + difference_type(__n));
662         this->_M_deallocate();
663         this->_M_end_of_storage = __q + (__len + _S_word_bit - 1)/_S_word_bit;
664         this->_M_start = iterator(__q, 0);
665       }
666     }
667   
668     void insert(iterator __position, size_type __n, bool __x) {
669       _M_fill_insert(__position, __n, __x);
670     }
671   
672     void pop_back() { --this->_M_finish; }
673     iterator erase(iterator __position) {
674       if (__position + 1 != end())
675         std::copy(__position + 1, end(), __position);
676         --this->_M_finish;
677       return __position;
678     }
679     iterator erase(iterator __first, iterator __last) {
680       this->_M_finish = std::copy(__last, end(), __first);
681       return __first;
682     }
683     void resize(size_type __new_size, bool __x = bool()) {
684       if (__new_size < size()) 
685         erase(begin() + difference_type(__new_size), end());
686       else
687         insert(end(), __new_size - size(), __x);
688     }
689     void flip() {
690       for (_Bit_type * __p = this->_M_start._M_p;
691            __p != this->_M_end_of_storage;
692            ++__p)
693         *__p = ~*__p;
694     }
695   
696     void clear() { erase(begin(), end()); }
697   };
698
699   // This typedef is non-standard.  It is provided for backward compatibility.
700   typedef vector<bool, __alloc> bit_vector;
701 } // namespace __gnu_norm
702
703 #endif /* _BVECTOR_H */