]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/include/bits/stl_bvector.h
c_io_stdio.h: Correct grammar in comments.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / stl_bvector.h
1 // bit_vector and vector<bool> specialization -*- C++ -*-
2
3 // Copyright (C) 2001 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 __SGI_STL_INTERNAL_BVECTOR_H
62 #define __SGI_STL_INTERNAL_BVECTOR_H
63
64 namespace std
65 {
66
67 static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));
68
69 struct _Bit_reference {
70 unsigned int* _M_p;
71 unsigned int _M_mask;
72 _Bit_reference(unsigned int* __x, unsigned int __y)
73 : _M_p(__x), _M_mask(__y) {}
74
75 public:
76 _Bit_reference() : _M_p(0), _M_mask(0) {}
77 operator bool() const { return !(!(*_M_p & _M_mask)); }
78 _Bit_reference& operator=(bool __x)
79 {
80 if (__x) *_M_p |= _M_mask;
81 else *_M_p &= ~_M_mask;
82 return *this;
83 }
84 _Bit_reference& operator=(const _Bit_reference& __x)
85 { return *this = bool(__x); }
86 bool operator==(const _Bit_reference& __x) const
87 { return bool(*this) == bool(__x); }
88 bool operator<(const _Bit_reference& __x) const {
89 return !bool(*this) && bool(__x);
90 }
91 void flip() { *_M_p ^= _M_mask; }
92 };
93
94 inline void swap(_Bit_reference __x, _Bit_reference __y)
95 {
96 bool __tmp = __x;
97 __x = __y;
98 __y = __tmp;
99 }
100
101 struct _Bit_iterator_base : public random_access_iterator<bool, ptrdiff_t>
102 {
103 unsigned int* _M_p;
104 unsigned int _M_offset;
105
106 _Bit_iterator_base(unsigned int* __x, unsigned int __y)
107 : _M_p(__x), _M_offset(__y) {}
108
109 void _M_bump_up() {
110 if (_M_offset++ == __WORD_BIT - 1) {
111 _M_offset = 0;
112 ++_M_p;
113 }
114 }
115 void _M_bump_down() {
116 if (_M_offset-- == 0) {
117 _M_offset = __WORD_BIT - 1;
118 --_M_p;
119 }
120 }
121
122 void _M_incr(ptrdiff_t __i) {
123 difference_type __n = __i + _M_offset;
124 _M_p += __n / __WORD_BIT;
125 __n = __n % __WORD_BIT;
126 if (__n < 0) {
127 _M_offset = (unsigned int) __n + __WORD_BIT;
128 --_M_p;
129 } else
130 _M_offset = (unsigned int) __n;
131 }
132
133 bool operator==(const _Bit_iterator_base& __i) const {
134 return _M_p == __i._M_p && _M_offset == __i._M_offset;
135 }
136 bool operator<(const _Bit_iterator_base& __i) const {
137 return _M_p < __i._M_p || (_M_p == __i._M_p && _M_offset < __i._M_offset);
138 }
139 bool operator!=(const _Bit_iterator_base& __i) const {
140 return !(*this == __i);
141 }
142 bool operator>(const _Bit_iterator_base& __i) const {
143 return __i < *this;
144 }
145 bool operator<=(const _Bit_iterator_base& __i) const {
146 return !(__i < *this);
147 }
148 bool operator>=(const _Bit_iterator_base& __i) const {
149 return !(*this < __i);
150 }
151 };
152
153 inline ptrdiff_t
154 operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
155 return __WORD_BIT * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset;
156 }
157
158
159 struct _Bit_iterator : public _Bit_iterator_base
160 {
161 typedef _Bit_reference reference;
162 typedef _Bit_reference* pointer;
163 typedef _Bit_iterator iterator;
164
165 _Bit_iterator() : _Bit_iterator_base(0, 0) {}
166 _Bit_iterator(unsigned int* __x, unsigned int __y)
167 : _Bit_iterator_base(__x, __y) {}
168
169 reference operator*() const { return reference(_M_p, 1U << _M_offset); }
170 iterator& operator++() {
171 _M_bump_up();
172 return *this;
173 }
174 iterator operator++(int) {
175 iterator __tmp = *this;
176 _M_bump_up();
177 return __tmp;
178 }
179 iterator& operator--() {
180 _M_bump_down();
181 return *this;
182 }
183 iterator operator--(int) {
184 iterator __tmp = *this;
185 _M_bump_down();
186 return __tmp;
187 }
188 iterator& operator+=(difference_type __i) {
189 _M_incr(__i);
190 return *this;
191 }
192 iterator& operator-=(difference_type __i) {
193 *this += -__i;
194 return *this;
195 }
196 iterator operator+(difference_type __i) const {
197 iterator __tmp = *this;
198 return __tmp += __i;
199 }
200 iterator operator-(difference_type __i) const {
201 iterator __tmp = *this;
202 return __tmp -= __i;
203 }
204
205 reference operator[](difference_type __i) { return *(*this + __i); }
206 };
207
208 inline _Bit_iterator
209 operator+(ptrdiff_t __n, const _Bit_iterator& __x) { return __x + __n; }
210
211
212 struct _Bit_const_iterator : public _Bit_iterator_base
213 {
214 typedef bool reference;
215 typedef bool const_reference;
216 typedef const bool* pointer;
217 typedef _Bit_const_iterator const_iterator;
218
219 _Bit_const_iterator() : _Bit_iterator_base(0, 0) {}
220 _Bit_const_iterator(unsigned int* __x, unsigned int __y)
221 : _Bit_iterator_base(__x, __y) {}
222 _Bit_const_iterator(const _Bit_iterator& __x)
223 : _Bit_iterator_base(__x._M_p, __x._M_offset) {}
224
225 const_reference operator*() const {
226 return _Bit_reference(_M_p, 1U << _M_offset);
227 }
228 const_iterator& operator++() {
229 _M_bump_up();
230 return *this;
231 }
232 const_iterator operator++(int) {
233 const_iterator __tmp = *this;
234 _M_bump_up();
235 return __tmp;
236 }
237 const_iterator& operator--() {
238 _M_bump_down();
239 return *this;
240 }
241 const_iterator operator--(int) {
242 const_iterator __tmp = *this;
243 _M_bump_down();
244 return __tmp;
245 }
246 const_iterator& operator+=(difference_type __i) {
247 _M_incr(__i);
248 return *this;
249 }
250 const_iterator& operator-=(difference_type __i) {
251 *this += -__i;
252 return *this;
253 }
254 const_iterator operator+(difference_type __i) const {
255 const_iterator __tmp = *this;
256 return __tmp += __i;
257 }
258 const_iterator operator-(difference_type __i) const {
259 const_iterator __tmp = *this;
260 return __tmp -= __i;
261 }
262 const_reference operator[](difference_type __i) {
263 return *(*this + __i);
264 }
265 };
266
267 inline _Bit_const_iterator
268 operator+(ptrdiff_t __n, const _Bit_const_iterator& __x) { return __x + __n; }
269
270
271 // Bit-vector base class, which encapsulates the difference between
272 // old SGI-style allocators and standard-conforming allocators.
273
274 // Base class for ordinary allocators.
275 template <class _Allocator, bool __is_static>
276 class _Bvector_alloc_base {
277 public:
278 typedef typename _Alloc_traits<bool, _Allocator>::allocator_type
279 allocator_type;
280 allocator_type get_allocator() const { return _M_data_allocator; }
281
282 _Bvector_alloc_base(const allocator_type& __a)
283 : _M_data_allocator(__a), _M_start(), _M_finish(), _M_end_of_storage(0) {}
284
285 protected:
286 unsigned int* _M_bit_alloc(size_t __n)
287 { return _M_data_allocator.allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
288 void _M_deallocate() {
289 if (_M_start._M_p)
290 _M_data_allocator.deallocate(_M_start._M_p,
291 _M_end_of_storage - _M_start._M_p);
292 }
293
294 typename _Alloc_traits<unsigned int, _Allocator>::allocator_type
295 _M_data_allocator;
296 _Bit_iterator _M_start;
297 _Bit_iterator _M_finish;
298 unsigned int* _M_end_of_storage;
299 };
300
301 // Specialization for instanceless allocators.
302 template <class _Allocator>
303 class _Bvector_alloc_base<_Allocator, true> {
304 public:
305 typedef typename _Alloc_traits<bool, _Allocator>::allocator_type
306 allocator_type;
307 allocator_type get_allocator() const { return allocator_type(); }
308
309 _Bvector_alloc_base(const allocator_type&)
310 : _M_start(), _M_finish(), _M_end_of_storage(0) {}
311
312 protected:
313 typedef typename _Alloc_traits<unsigned int, _Allocator>::_Alloc_type
314 _Alloc_type;
315
316 unsigned int* _M_bit_alloc(size_t __n)
317 { return _Alloc_type::allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
318 void _M_deallocate() {
319 if (_M_start._M_p)
320 _Alloc_type::deallocate(_M_start._M_p,
321 _M_end_of_storage - _M_start._M_p);
322 }
323
324 _Bit_iterator _M_start;
325 _Bit_iterator _M_finish;
326 unsigned int* _M_end_of_storage;
327 };
328
329 template <class _Alloc>
330 class _Bvector_base
331 : public _Bvector_alloc_base<_Alloc,
332 _Alloc_traits<bool, _Alloc>::_S_instanceless>
333 {
334 typedef _Bvector_alloc_base<_Alloc,
335 _Alloc_traits<bool, _Alloc>::_S_instanceless>
336 _Base;
337 public:
338 typedef typename _Base::allocator_type allocator_type;
339
340 _Bvector_base(const allocator_type& __a) : _Base(__a) {}
341 ~_Bvector_base() { _Base::_M_deallocate(); }
342 };
343
344 } // namespace std
345
346 // Declare a partial specialization of vector<T, Alloc>.
347 #include <bits/stl_vector.h>
348 namespace std
349 {
350
351 template <typename _Alloc>
352 class vector<bool, _Alloc> : public _Bvector_base<_Alloc>
353 {
354 public:
355 typedef bool value_type;
356 typedef size_t size_type;
357 typedef ptrdiff_t difference_type;
358 typedef _Bit_reference reference;
359 typedef bool const_reference;
360 typedef _Bit_reference* pointer;
361 typedef const bool* const_pointer;
362
363 typedef _Bit_iterator iterator;
364 typedef _Bit_const_iterator const_iterator;
365
366 typedef reverse_iterator<const_iterator> const_reverse_iterator;
367 typedef reverse_iterator<iterator> reverse_iterator;
368
369 typedef typename _Bvector_base<_Alloc>::allocator_type allocator_type;
370 allocator_type get_allocator() const {
371 return _Bvector_base<_Alloc>::get_allocator();
372 }
373
374 protected:
375 using _Bvector_base<_Alloc>::_M_bit_alloc;
376 using _Bvector_base<_Alloc>::_M_deallocate;
377 using _Bvector_base<_Alloc>::_M_start;
378 using _Bvector_base<_Alloc>::_M_finish;
379 using _Bvector_base<_Alloc>::_M_end_of_storage;
380
381 protected:
382 void _M_initialize(size_type __n) {
383 unsigned int* __q = _M_bit_alloc(__n);
384 _M_end_of_storage = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
385 _M_start = iterator(__q, 0);
386 _M_finish = _M_start + difference_type(__n);
387 }
388 void _M_insert_aux(iterator __position, bool __x) {
389 if (_M_finish._M_p != _M_end_of_storage) {
390 copy_backward(__position, _M_finish, _M_finish + 1);
391 *__position = __x;
392 ++_M_finish;
393 }
394 else {
395 size_type __len = size() ? 2 * size() : __WORD_BIT;
396 unsigned int* __q = _M_bit_alloc(__len);
397 iterator __i = copy(begin(), __position, iterator(__q, 0));
398 *__i++ = __x;
399 _M_finish = copy(__position, end(), __i);
400 _M_deallocate();
401 _M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
402 _M_start = iterator(__q, 0);
403 }
404 }
405
406 template <class _InputIterator>
407 void _M_initialize_range(_InputIterator __first, _InputIterator __last,
408 input_iterator_tag) {
409 _M_start = iterator();
410 _M_finish = iterator();
411 _M_end_of_storage = 0;
412 for ( ; __first != __last; ++__first)
413 push_back(*__first);
414 }
415
416 template <class _ForwardIterator>
417 void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
418 forward_iterator_tag) {
419 size_type __n = 0;
420 distance(__first, __last, __n);
421 _M_initialize(__n);
422 copy(__first, __last, _M_start);
423 }
424
425 template <class _InputIterator>
426 void _M_insert_range(iterator __pos,
427 _InputIterator __first, _InputIterator __last,
428 input_iterator_tag) {
429 for ( ; __first != __last; ++__first) {
430 __pos = insert(__pos, *__first);
431 ++__pos;
432 }
433 }
434
435 template <class _ForwardIterator>
436 void _M_insert_range(iterator __position,
437 _ForwardIterator __first, _ForwardIterator __last,
438 forward_iterator_tag) {
439 if (__first != __last) {
440 size_type __n = 0;
441 distance(__first, __last, __n);
442 if (capacity() - size() >= __n) {
443 copy_backward(__position, end(), _M_finish + difference_type(__n));
444 copy(__first, __last, __position);
445 _M_finish += difference_type(__n);
446 }
447 else {
448 size_type __len = size() + max(size(), __n);
449 unsigned int* __q = _M_bit_alloc(__len);
450 iterator __i = copy(begin(), __position, iterator(__q, 0));
451 __i = copy(__first, __last, __i);
452 _M_finish = copy(__position, end(), __i);
453 _M_deallocate();
454 _M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
455 _M_start = iterator(__q, 0);
456 }
457 }
458 }
459
460 public:
461 iterator begin() { return _M_start; }
462 const_iterator begin() const { return _M_start; }
463 iterator end() { return _M_finish; }
464 const_iterator end() const { return _M_finish; }
465
466 reverse_iterator rbegin() { return reverse_iterator(end()); }
467 const_reverse_iterator rbegin() const {
468 return const_reverse_iterator(end());
469 }
470 reverse_iterator rend() { return reverse_iterator(begin()); }
471 const_reverse_iterator rend() const {
472 return const_reverse_iterator(begin());
473 }
474
475 size_type size() const { return size_type(end() - begin()); }
476 size_type max_size() const { return size_type(-1); }
477 size_type capacity() const {
478 return size_type(const_iterator(_M_end_of_storage, 0) - begin());
479 }
480 bool empty() const { return begin() == end(); }
481
482 reference operator[](size_type __n)
483 { return *(begin() + difference_type(__n)); }
484 const_reference operator[](size_type __n) const
485 { return *(begin() + difference_type(__n)); }
486
487 void _M_range_check(size_type __n) const {
488 if (__n >= this->size())
489 __throw_out_of_range("vector<bool>");
490 }
491
492 reference at(size_type __n)
493 { _M_range_check(__n); return (*this)[__n]; }
494 const_reference at(size_type __n) const
495 { _M_range_check(__n); return (*this)[__n]; }
496
497 explicit vector(const allocator_type& __a = allocator_type())
498 : _Bvector_base<_Alloc>(__a) {}
499
500 vector(size_type __n, bool __value,
501 const allocator_type& __a = allocator_type())
502 : _Bvector_base<_Alloc>(__a)
503 {
504 _M_initialize(__n);
505 fill(_M_start._M_p, _M_end_of_storage, __value ? ~0 : 0);
506 }
507
508 explicit vector(size_type __n)
509 : _Bvector_base<_Alloc>(allocator_type())
510 {
511 _M_initialize(__n);
512 fill(_M_start._M_p, _M_end_of_storage, 0);
513 }
514
515 vector(const vector& __x) : _Bvector_base<_Alloc>(__x.get_allocator()) {
516 _M_initialize(__x.size());
517 copy(__x.begin(), __x.end(), _M_start);
518 }
519
520 // Check whether it's an integral type. If so, it's not an iterator.
521
522 template <class _Integer>
523 void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) {
524 _M_initialize(__n);
525 fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
526 }
527
528 template <class _InputIterator>
529 void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
530 __false_type) {
531 _M_initialize_range(__first, __last, __iterator_category(__first));
532 }
533
534 template <class _InputIterator>
535 vector(_InputIterator __first, _InputIterator __last,
536 const allocator_type& __a = allocator_type())
537 : _Bvector_base<_Alloc>(__a)
538 {
539 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
540 _M_initialize_dispatch(__first, __last, _Integral());
541 }
542
543 ~vector() { }
544
545 vector& operator=(const vector& __x) {
546 if (&__x == this) return *this;
547 if (__x.size() > capacity()) {
548 _M_deallocate();
549 _M_initialize(__x.size());
550 }
551 copy(__x.begin(), __x.end(), begin());
552 _M_finish = begin() + difference_type(__x.size());
553 return *this;
554 }
555
556 // assign(), a generalized assignment member function. Two
557 // versions: one that takes a count, and one that takes a range.
558 // The range version is a member template, so we dispatch on whether
559 // or not the type is an integer.
560
561 void _M_fill_assign(size_t __n, bool __x) {
562 if (__n > size()) {
563 fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
564 insert(end(), __n - size(), __x);
565 }
566 else {
567 erase(begin() + __n, end());
568 fill(_M_start._M_p, _M_end_of_storage, __x ? ~0 : 0);
569 }
570 }
571
572 void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
573
574 template <class _InputIterator>
575 void assign(_InputIterator __first, _InputIterator __last) {
576 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
577 _M_assign_dispatch(__first, __last, _Integral());
578 }
579
580 template <class _Integer>
581 void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
582 { _M_fill_assign((size_t) __n, (bool) __val); }
583
584 template <class _InputIter>
585 void _M_assign_dispatch(_InputIter __first, _InputIter __last, __false_type)
586 { _M_assign_aux(__first, __last, __iterator_category(__first)); }
587
588 template <class _InputIterator>
589 void _M_assign_aux(_InputIterator __first, _InputIterator __last,
590 input_iterator_tag) {
591 iterator __cur = begin();
592 for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
593 *__cur = *__first;
594 if (__first == __last)
595 erase(__cur, end());
596 else
597 insert(end(), __first, __last);
598 }
599
600 template <class _ForwardIterator>
601 void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
602 forward_iterator_tag) {
603 size_type __len = 0;
604 distance(__first, __last, __len);
605 if (__len < size())
606 erase(copy(__first, __last, begin()), end());
607 else {
608 _ForwardIterator __mid = __first;
609 advance(__mid, size());
610 copy(__first, __mid, begin());
611 insert(end(), __mid, __last);
612 }
613 }
614
615 void reserve(size_type __n) {
616 if (capacity() < __n) {
617 unsigned int* __q = _M_bit_alloc(__n);
618 _M_finish = copy(begin(), end(), iterator(__q, 0));
619 _M_deallocate();
620 _M_start = iterator(__q, 0);
621 _M_end_of_storage = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
622 }
623 }
624
625 reference front() { return *begin(); }
626 const_reference front() const { return *begin(); }
627 reference back() { return *(end() - 1); }
628 const_reference back() const { return *(end() - 1); }
629 void push_back(bool __x) {
630 if (_M_finish._M_p != _M_end_of_storage)
631 *_M_finish++ = __x;
632 else
633 _M_insert_aux(end(), __x);
634 }
635 void swap(vector<bool, _Alloc>& __x) {
636 std::swap(_M_start, __x._M_start);
637 std::swap(_M_finish, __x._M_finish);
638 std::swap(_M_end_of_storage, __x._M_end_of_storage);
639 }
640 iterator insert(iterator __position, bool __x = bool()) {
641 difference_type __n = __position - begin();
642 if (_M_finish._M_p != _M_end_of_storage && __position == end())
643 *_M_finish++ = __x;
644 else
645 _M_insert_aux(__position, __x);
646 return begin() + __n;
647 }
648
649 // Check whether it's an integral type. If so, it's not an iterator.
650
651 template <class _Integer>
652 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
653 __true_type) {
654 _M_fill_insert(__pos, __n, __x);
655 }
656
657 template <class _InputIterator>
658 void _M_insert_dispatch(iterator __pos,
659 _InputIterator __first, _InputIterator __last,
660 __false_type) {
661 _M_insert_range(__pos, __first, __last, __iterator_category(__first));
662 }
663
664 template <class _InputIterator>
665 void insert(iterator __position,
666 _InputIterator __first, _InputIterator __last) {
667 typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
668 _M_insert_dispatch(__position, __first, __last, _Integral());
669 }
670
671 void _M_fill_insert(iterator __position, size_type __n, bool __x) {
672 if (__n == 0) return;
673 if (capacity() - size() >= __n) {
674 copy_backward(__position, end(), _M_finish + difference_type(__n));
675 fill(__position, __position + difference_type(__n), __x);
676 _M_finish += difference_type(__n);
677 }
678 else {
679 size_type __len = size() + max(size(), __n);
680 unsigned int* __q = _M_bit_alloc(__len);
681 iterator __i = copy(begin(), __position, iterator(__q, 0));
682 fill_n(__i, __n, __x);
683 _M_finish = copy(__position, end(), __i + difference_type(__n));
684 _M_deallocate();
685 _M_end_of_storage = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
686 _M_start = iterator(__q, 0);
687 }
688 }
689
690 void insert(iterator __position, size_type __n, bool __x) {
691 _M_fill_insert(__position, __n, __x);
692 }
693
694 void pop_back() { --_M_finish; }
695 iterator erase(iterator __position) {
696 if (__position + 1 != end())
697 copy(__position + 1, end(), __position);
698 --_M_finish;
699 return __position;
700 }
701 iterator erase(iterator __first, iterator __last) {
702 _M_finish = copy(__last, end(), __first);
703 return __first;
704 }
705 void resize(size_type __new_size, bool __x = bool()) {
706 if (__new_size < size())
707 erase(begin() + difference_type(__new_size), end());
708 else
709 insert(end(), __new_size - size(), __x);
710 }
711 void flip() {
712 for (unsigned int* __p = _M_start._M_p; __p != _M_end_of_storage; ++__p)
713 *__p = ~*__p;
714 }
715
716 void clear() { erase(begin(), end()); }
717 };
718
719 // This typedef is non-standard. It is provided for backward compatibility.
720 typedef vector<bool, alloc> bit_vector;
721
722 } // namespace std
723
724 #endif /* __SGI_STL_INTERNAL_BVECTOR_H */
725
726 // Local Variables:
727 // mode:C++
728 // End: