Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libstdc++-v3 / include / bits / stl_bvector.h
blob74985071baa9804d510555cf699b3f9a6bba31f3
1 // vector<bool> specialization -*- C++ -*-
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005 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.
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.
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.
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.
32 * Copyright (c) 1994
33 * Hewlett-Packard Company
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.
44 * Copyright (c) 1996-1999
45 * Silicon Graphics Computer Systems, Inc.
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.
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.
61 #ifndef _BVECTOR_H
62 #define _BVECTOR_H 1
64 namespace _GLIBCXX_STD
66 typedef unsigned long _Bit_type;
67 enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) };
69 struct _Bit_reference
71 _Bit_type * _M_p;
72 _Bit_type _M_mask;
74 _Bit_reference(_Bit_type * __x, _Bit_type __y)
75 : _M_p(__x), _M_mask(__y) { }
77 _Bit_reference() : _M_p(0), _M_mask(0) { }
79 operator bool() const
80 { return !!(*_M_p & _M_mask); }
82 _Bit_reference&
83 operator=(bool __x)
85 if (__x)
86 *_M_p |= _M_mask;
87 else
88 *_M_p &= ~_M_mask;
89 return *this;
92 _Bit_reference&
93 operator=(const _Bit_reference& __x)
94 { return *this = bool(__x); }
96 bool
97 operator==(const _Bit_reference& __x) const
98 { return bool(*this) == bool(__x); }
100 bool
101 operator<(const _Bit_reference& __x) const
102 { return !bool(*this) && bool(__x); }
104 void
105 flip()
106 { *_M_p ^= _M_mask; }
109 struct _Bit_iterator_base : public iterator<random_access_iterator_tag, bool>
111 _Bit_type * _M_p;
112 unsigned int _M_offset;
114 _Bit_iterator_base(_Bit_type * __x, unsigned int __y)
115 : _M_p(__x), _M_offset(__y) { }
117 void
118 _M_bump_up()
120 if (_M_offset++ == _S_word_bit - 1)
122 _M_offset = 0;
123 ++_M_p;
127 void
128 _M_bump_down()
130 if (_M_offset-- == 0)
132 _M_offset = _S_word_bit - 1;
133 --_M_p;
137 void
138 _M_incr(ptrdiff_t __i)
140 difference_type __n = __i + _M_offset;
141 _M_p += __n / _S_word_bit;
142 __n = __n % _S_word_bit;
143 if (__n < 0)
145 _M_offset = static_cast<unsigned int>(__n + _S_word_bit);
146 --_M_p;
148 else
149 _M_offset = static_cast<unsigned int>(__n);
152 bool
153 operator==(const _Bit_iterator_base& __i) const
154 { return _M_p == __i._M_p && _M_offset == __i._M_offset; }
156 bool
157 operator<(const _Bit_iterator_base& __i) const
159 return _M_p < __i._M_p
160 || (_M_p == __i._M_p && _M_offset < __i._M_offset);
163 bool
164 operator!=(const _Bit_iterator_base& __i) const
165 { return !(*this == __i); }
167 bool
168 operator>(const _Bit_iterator_base& __i) const
169 { return __i < *this; }
171 bool
172 operator<=(const _Bit_iterator_base& __i) const
173 { return !(__i < *this); }
175 bool
176 operator>=(const _Bit_iterator_base& __i) const
177 { return !(*this < __i); }
180 inline ptrdiff_t
181 operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
183 return _S_word_bit * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset;
186 struct _Bit_iterator : public _Bit_iterator_base
188 typedef _Bit_reference reference;
189 typedef _Bit_reference* pointer;
190 typedef _Bit_iterator iterator;
192 _Bit_iterator() : _Bit_iterator_base(0, 0) { }
194 _Bit_iterator(_Bit_type * __x, unsigned int __y)
195 : _Bit_iterator_base(__x, __y) { }
197 reference
198 operator*() const
199 { return reference(_M_p, 1UL << _M_offset); }
201 iterator&
202 operator++()
204 _M_bump_up();
205 return *this;
208 iterator
209 operator++(int)
211 iterator __tmp = *this;
212 _M_bump_up();
213 return __tmp;
216 iterator&
217 operator--()
219 _M_bump_down();
220 return *this;
223 iterator
224 operator--(int)
226 iterator __tmp = *this;
227 _M_bump_down();
228 return __tmp;
231 iterator&
232 operator+=(difference_type __i)
234 _M_incr(__i);
235 return *this;
238 iterator&
239 operator-=(difference_type __i)
241 *this += -__i;
242 return *this;
245 iterator
246 operator+(difference_type __i) const
248 iterator __tmp = *this;
249 return __tmp += __i;
252 iterator
253 operator-(difference_type __i) const
255 iterator __tmp = *this;
256 return __tmp -= __i;
259 reference
260 operator[](difference_type __i)
261 { return *(*this + __i); }
264 inline _Bit_iterator
265 operator+(ptrdiff_t __n, const _Bit_iterator& __x)
266 { return __x + __n; }
268 struct _Bit_const_iterator : public _Bit_iterator_base
270 typedef bool reference;
271 typedef bool const_reference;
272 typedef const bool* pointer;
273 typedef _Bit_const_iterator const_iterator;
275 _Bit_const_iterator() : _Bit_iterator_base(0, 0) { }
277 _Bit_const_iterator(_Bit_type * __x, unsigned int __y)
278 : _Bit_iterator_base(__x, __y) { }
280 _Bit_const_iterator(const _Bit_iterator& __x)
281 : _Bit_iterator_base(__x._M_p, __x._M_offset) { }
283 const_reference
284 operator*() const
285 { return _Bit_reference(_M_p, 1UL << _M_offset); }
287 const_iterator&
288 operator++()
290 _M_bump_up();
291 return *this;
294 const_iterator
295 operator++(int)
297 const_iterator __tmp = *this;
298 _M_bump_up();
299 return __tmp;
302 const_iterator&
303 operator--()
305 _M_bump_down();
306 return *this;
309 const_iterator
310 operator--(int)
312 const_iterator __tmp = *this;
313 _M_bump_down();
314 return __tmp;
317 const_iterator&
318 operator+=(difference_type __i)
320 _M_incr(__i);
321 return *this;
324 const_iterator&
325 operator-=(difference_type __i)
327 *this += -__i;
328 return *this;
331 const_iterator
332 operator+(difference_type __i) const
334 const_iterator __tmp = *this;
335 return __tmp += __i;
338 const_iterator
339 operator-(difference_type __i) const
341 const_iterator __tmp = *this;
342 return __tmp -= __i;
345 const_reference
346 operator[](difference_type __i)
347 { return *(*this + __i); }
350 inline _Bit_const_iterator
351 operator+(ptrdiff_t __n, const _Bit_const_iterator& __x)
352 { return __x + __n; }
354 template<class _Alloc>
355 class _Bvector_base
357 typedef typename _Alloc::template rebind<_Bit_type>::other
358 _Bit_alloc_type;
360 struct _Bvector_impl : public _Bit_alloc_type
362 _Bit_iterator _M_start;
363 _Bit_iterator _M_finish;
364 _Bit_type* _M_end_of_storage;
365 _Bvector_impl(const _Bit_alloc_type& __a)
366 : _Bit_alloc_type(__a), _M_start(), _M_finish(), _M_end_of_storage(0)
370 public:
371 typedef _Alloc allocator_type;
373 allocator_type
374 get_allocator() const
375 { return *static_cast<const _Bit_alloc_type*>(&this->_M_impl); }
377 _Bvector_base(const allocator_type& __a) : _M_impl(__a) { }
379 ~_Bvector_base()
380 { this->_M_deallocate(); }
382 protected:
383 _Bvector_impl _M_impl;
385 _Bit_type*
386 _M_allocate(size_t __n)
387 { return _M_impl.allocate((__n + _S_word_bit - 1) / _S_word_bit); }
389 void
390 _M_deallocate()
392 if (_M_impl._M_start._M_p)
393 _M_impl.deallocate(_M_impl._M_start._M_p,
394 _M_impl._M_end_of_storage - _M_impl._M_start._M_p);
397 } // namespace std
399 // Declare a partial specialization of vector<T, Alloc>.
400 #include <bits/stl_vector.h>
402 namespace _GLIBCXX_STD
405 * @brief A specialization of vector for booleans which offers fixed time
406 * access to individual elements in any order.
408 * Note that vector<bool> does not actually meet the requirements for being
409 * a container. This is because the reference and pointer types are not
410 * really references and pointers to bool. See DR96 for details. @see
411 * vector for function documentation.
413 * @ingroup Containers
414 * @ingroup Sequences
416 * In some terminology a %vector can be described as a dynamic
417 * C-style array, it offers fast and efficient access to individual
418 * elements in any order and saves the user from worrying about
419 * memory and size allocation. Subscripting ( @c [] ) access is
420 * also provided as with C-style arrays.
422 template<typename _Alloc>
423 class vector<bool, _Alloc> : public _Bvector_base<_Alloc>
425 public:
426 typedef bool value_type;
427 typedef size_t size_type;
428 typedef ptrdiff_t difference_type;
429 typedef _Bit_reference reference;
430 typedef bool const_reference;
431 typedef _Bit_reference* pointer;
432 typedef const bool* const_pointer;
434 typedef _Bit_iterator iterator;
435 typedef _Bit_const_iterator const_iterator;
437 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
438 typedef std::reverse_iterator<iterator> reverse_iterator;
440 typedef typename _Bvector_base<_Alloc>::allocator_type allocator_type;
442 allocator_type get_allocator() const
443 { return _Bvector_base<_Alloc>::get_allocator(); }
445 protected:
446 using _Bvector_base<_Alloc>::_M_allocate;
447 using _Bvector_base<_Alloc>::_M_deallocate;
449 protected:
450 void
451 _M_initialize(size_type __n)
453 _Bit_type* __q = this->_M_allocate(__n);
454 this->_M_impl._M_end_of_storage = (__q
455 + ((__n + _S_word_bit - 1)
456 / _S_word_bit));
457 this->_M_impl._M_start = iterator(__q, 0);
458 this->_M_impl._M_finish = this->_M_impl._M_start + difference_type(__n);
461 void
462 _M_insert_aux(iterator __position, bool __x)
464 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
466 std::copy_backward(__position, this->_M_impl._M_finish,
467 this->_M_impl._M_finish + 1);
468 *__position = __x;
469 ++this->_M_impl._M_finish;
471 else
473 const size_type __len = size() ? 2 * size()
474 : static_cast<size_type>(_S_word_bit);
475 _Bit_type * __q = this->_M_allocate(__len);
476 iterator __i = std::copy(begin(), __position, iterator(__q, 0));
477 *__i++ = __x;
478 this->_M_impl._M_finish = std::copy(__position, end(), __i);
479 this->_M_deallocate();
480 this->_M_impl._M_end_of_storage = (__q + ((__len + _S_word_bit - 1)
481 / _S_word_bit));
482 this->_M_impl._M_start = iterator(__q, 0);
486 template<class _InputIterator>
487 void
488 _M_initialize_range(_InputIterator __first, _InputIterator __last,
489 input_iterator_tag)
491 this->_M_impl._M_start = iterator();
492 this->_M_impl._M_finish = iterator();
493 this->_M_impl._M_end_of_storage = 0;
494 for (; __first != __last; ++__first)
495 push_back(*__first);
498 template<class _ForwardIterator>
499 void
500 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
501 forward_iterator_tag)
503 const size_type __n = std::distance(__first, __last);
504 _M_initialize(__n);
505 std::copy(__first, __last, this->_M_impl._M_start);
508 template<class _InputIterator>
509 void
510 _M_insert_range(iterator __pos, _InputIterator __first,
511 _InputIterator __last, input_iterator_tag)
513 for (; __first != __last; ++__first)
515 __pos = insert(__pos, *__first);
516 ++__pos;
520 template<class _ForwardIterator>
521 void
522 _M_insert_range(iterator __position, _ForwardIterator __first,
523 _ForwardIterator __last, forward_iterator_tag)
525 if (__first != __last)
527 size_type __n = std::distance(__first, __last);
528 if (capacity() - size() >= __n)
530 std::copy_backward(__position, end(),
531 this->_M_impl._M_finish
532 + difference_type(__n));
533 std::copy(__first, __last, __position);
534 this->_M_impl._M_finish += difference_type(__n);
536 else
538 const size_type __len = size() + std::max(size(), __n);
539 _Bit_type * __q = this->_M_allocate(__len);
540 iterator __i = std::copy(begin(), __position,
541 iterator(__q, 0));
542 __i = std::copy(__first, __last, __i);
543 this->_M_impl._M_finish = std::copy(__position, end(), __i);
544 this->_M_deallocate();
545 this->_M_impl._M_end_of_storage = (__q
546 + ((__len + _S_word_bit - 1)
547 / _S_word_bit));
548 this->_M_impl._M_start = iterator(__q, 0);
553 public:
554 iterator
555 begin()
556 { return this->_M_impl._M_start; }
558 const_iterator
559 begin() const
560 { return this->_M_impl._M_start; }
562 iterator
563 end()
564 { return this->_M_impl._M_finish; }
566 const_iterator
567 end() const
568 { return this->_M_impl._M_finish; }
570 reverse_iterator
571 rbegin()
572 { return reverse_iterator(end()); }
574 const_reverse_iterator
575 rbegin() const
576 { return const_reverse_iterator(end()); }
578 reverse_iterator
579 rend()
580 { return reverse_iterator(begin()); }
582 const_reverse_iterator
583 rend() const
584 { return const_reverse_iterator(begin()); }
586 size_type
587 size() const
588 { return size_type(end() - begin()); }
590 size_type
591 max_size() const
592 { return size_type(-1); }
594 size_type
595 capacity() const
596 { return size_type(const_iterator(this->_M_impl._M_end_of_storage, 0)
597 - begin()); }
598 bool
599 empty() const
600 { return begin() == end(); }
602 reference
603 operator[](size_type __n)
604 { return *(begin() + difference_type(__n)); }
606 const_reference
607 operator[](size_type __n) const
608 { return *(begin() + difference_type(__n)); }
610 void
611 _M_range_check(size_type __n) const
613 if (__n >= this->size())
614 __throw_out_of_range(__N("vector<bool>::_M_range_check"));
617 reference
618 at(size_type __n)
619 { _M_range_check(__n); return (*this)[__n]; }
621 const_reference
622 at(size_type __n) const
623 { _M_range_check(__n); return (*this)[__n]; }
625 explicit
626 vector(const allocator_type& __a = allocator_type())
627 : _Bvector_base<_Alloc>(__a) { }
629 vector(size_type __n, bool __value,
630 const allocator_type& __a = allocator_type())
631 : _Bvector_base<_Alloc>(__a)
633 _M_initialize(__n);
634 std::fill(this->_M_impl._M_start._M_p, this->_M_impl._M_end_of_storage,
635 __value ? ~0 : 0);
638 explicit
639 vector(size_type __n)
640 : _Bvector_base<_Alloc>(allocator_type())
642 _M_initialize(__n);
643 std::fill(this->_M_impl._M_start._M_p,
644 this->_M_impl._M_end_of_storage, 0);
647 vector(const vector& __x)
648 : _Bvector_base<_Alloc>(__x.get_allocator())
650 _M_initialize(__x.size());
651 std::copy(__x.begin(), __x.end(), this->_M_impl._M_start);
654 // Check whether it's an integral type. If so, it's not an iterator.
655 template<class _Integer>
656 void
657 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
659 _M_initialize(__n);
660 std::fill(this->_M_impl._M_start._M_p,
661 this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
664 template<class _InputIterator>
665 void
666 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
667 __false_type)
668 { _M_initialize_range(__first, __last,
669 std::__iterator_category(__first)); }
671 template<class _InputIterator>
672 vector(_InputIterator __first, _InputIterator __last,
673 const allocator_type& __a = allocator_type())
674 : _Bvector_base<_Alloc>(__a)
676 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
677 _M_initialize_dispatch(__first, __last, _Integral());
680 ~vector() { }
682 vector&
683 operator=(const vector& __x)
685 if (&__x == this)
686 return *this;
687 if (__x.size() > capacity())
689 this->_M_deallocate();
690 _M_initialize(__x.size());
692 std::copy(__x.begin(), __x.end(), begin());
693 this->_M_impl._M_finish = begin() + difference_type(__x.size());
694 return *this;
697 // assign(), a generalized assignment member function. Two
698 // versions: one that takes a count, and one that takes a range.
699 // The range version is a member template, so we dispatch on whether
700 // or not the type is an integer.
702 void
703 _M_fill_assign(size_t __n, bool __x)
705 if (__n > size())
707 std::fill(this->_M_impl._M_start._M_p,
708 this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
709 insert(end(), __n - size(), __x);
711 else
713 erase(begin() + __n, end());
714 std::fill(this->_M_impl._M_start._M_p,
715 this->_M_impl._M_end_of_storage, __x ? ~0 : 0);
719 void
720 assign(size_t __n, bool __x)
721 { _M_fill_assign(__n, __x); }
723 template<class _InputIterator>
724 void
725 assign(_InputIterator __first, _InputIterator __last)
727 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
728 _M_assign_dispatch(__first, __last, _Integral());
731 template<class _Integer>
732 void
733 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
734 { _M_fill_assign((size_t) __n, (bool) __val); }
736 template<class _InputIterator>
737 void
738 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
739 __false_type)
740 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
742 template<class _InputIterator>
743 void
744 _M_assign_aux(_InputIterator __first, _InputIterator __last,
745 input_iterator_tag)
747 iterator __cur = begin();
748 for (; __first != __last && __cur != end(); ++__cur, ++__first)
749 *__cur = *__first;
750 if (__first == __last)
751 erase(__cur, end());
752 else
753 insert(end(), __first, __last);
756 template<class _ForwardIterator>
757 void
758 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
759 forward_iterator_tag)
761 const size_type __len = std::distance(__first, __last);
762 if (__len < size())
763 erase(std::copy(__first, __last, begin()), end());
764 else
766 _ForwardIterator __mid = __first;
767 std::advance(__mid, size());
768 std::copy(__first, __mid, begin());
769 insert(end(), __mid, __last);
773 void
774 reserve(size_type __n)
776 if (__n > this->max_size())
777 __throw_length_error(__N("vector::reserve"));
778 if (this->capacity() < __n)
780 _Bit_type* __q = this->_M_allocate(__n);
781 this->_M_impl._M_finish = std::copy(begin(), end(),
782 iterator(__q, 0));
783 this->_M_deallocate();
784 this->_M_impl._M_start = iterator(__q, 0);
785 this->_M_impl._M_end_of_storage = (__q + (__n + _S_word_bit - 1)
786 / _S_word_bit);
790 reference
791 front()
792 { return *begin(); }
794 const_reference
795 front() const
796 { return *begin(); }
798 reference
799 back()
800 { return *(end() - 1); }
802 const_reference
803 back() const
804 { return *(end() - 1); }
806 void
807 push_back(bool __x)
809 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage)
810 *this->_M_impl._M_finish++ = __x;
811 else
812 _M_insert_aux(end(), __x);
815 void
816 swap(vector<bool, _Alloc>& __x)
818 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
819 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
820 std::swap(this->_M_impl._M_end_of_storage,
821 __x._M_impl._M_end_of_storage);
824 // [23.2.5]/1, third-to-last entry in synopsis listing
825 static void
826 swap(reference __x, reference __y)
828 bool __tmp = __x;
829 __x = __y;
830 __y = __tmp;
833 iterator
834 insert(iterator __position, bool __x = bool())
836 const difference_type __n = __position - begin();
837 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage
838 && __position == end())
839 *this->_M_impl._M_finish++ = __x;
840 else
841 _M_insert_aux(__position, __x);
842 return begin() + __n;
845 // Check whether it's an integral type. If so, it's not an iterator.
847 template<class _Integer>
848 void
849 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
850 __true_type)
851 { _M_fill_insert(__pos, __n, __x); }
853 template<class _InputIterator>
854 void
855 _M_insert_dispatch(iterator __pos,
856 _InputIterator __first, _InputIterator __last,
857 __false_type)
858 { _M_insert_range(__pos, __first, __last,
859 std::__iterator_category(__first)); }
861 template<class _InputIterator>
862 void
863 insert(iterator __position,
864 _InputIterator __first, _InputIterator __last)
866 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
867 _M_insert_dispatch(__position, __first, __last, _Integral());
870 void
871 _M_fill_insert(iterator __position, size_type __n, bool __x)
873 if (__n == 0)
874 return;
875 if (capacity() - size() >= __n)
877 std::copy_backward(__position, end(),
878 this->_M_impl._M_finish + difference_type(__n));
879 std::fill(__position, __position + difference_type(__n), __x);
880 this->_M_impl._M_finish += difference_type(__n);
882 else
884 const size_type __len = size() + std::max(size(), __n);
885 _Bit_type * __q = this->_M_allocate(__len);
886 iterator __i = std::copy(begin(), __position, iterator(__q, 0));
887 std::fill_n(__i, __n, __x);
888 this->_M_impl._M_finish = std::copy(__position, end(),
889 __i + difference_type(__n));
890 this->_M_deallocate();
891 this->_M_impl._M_end_of_storage = (__q + ((__len + _S_word_bit - 1)
892 / _S_word_bit));
893 this->_M_impl._M_start = iterator(__q, 0);
897 void
898 insert(iterator __position, size_type __n, bool __x)
899 { _M_fill_insert(__position, __n, __x); }
901 void
902 pop_back()
903 { --this->_M_impl._M_finish; }
905 iterator
906 erase(iterator __position)
908 if (__position + 1 != end())
909 std::copy(__position + 1, end(), __position);
910 --this->_M_impl._M_finish;
911 return __position;
914 iterator
915 erase(iterator __first, iterator __last)
917 this->_M_impl._M_finish = std::copy(__last, end(), __first);
918 return __first;
921 void
922 resize(size_type __new_size, bool __x = bool())
924 if (__new_size < size())
925 erase(begin() + difference_type(__new_size), end());
926 else
927 insert(end(), __new_size - size(), __x);
930 void
931 flip()
933 for (_Bit_type * __p = this->_M_impl._M_start._M_p;
934 __p != this->_M_impl._M_end_of_storage; ++__p)
935 *__p = ~*__p;
938 void
939 clear()
940 { erase(begin(), end()); }
942 } // namespace std
944 #endif