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