4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_BVECTOR_H
31 #define _STLP_INTERNAL_BVECTOR_H
33 #ifndef _STLP_INTERNAL_VECTOR_H
34 # include <stl/_vector.h>
37 #define _STLP_WORD_BIT (int(CHAR_BIT*sizeof(unsigned int)))
40 _STLP_MOVE_TO_PRIV_NAMESPACE
42 struct _Bit_reference {
45 _Bit_reference(unsigned int* __x, unsigned int __y)
46 : _M_p(__x), _M_mask(__y) {}
49 _Bit_reference() : _M_p(0), _M_mask(0) {}
51 operator bool() const {
52 return !(!(*_M_p & _M_mask));
54 _Bit_reference& operator = (bool __x) {
55 if (__x) *_M_p |= _M_mask;
56 else *_M_p &= ~_M_mask;
59 _Bit_reference& operator = (const _Bit_reference& __x) {
60 return *this = bool(__x);
62 bool operator == (const _Bit_reference& __x) const {
63 return bool(*this) == bool(__x);
65 bool operator < (const _Bit_reference& __x) const {
66 return !bool(*this) && bool(__x);
69 _Bit_reference& operator |= (bool __x) {
74 _Bit_reference& operator &= (bool __x) {
79 void flip() { *_M_p ^= _M_mask; }
83 _STLP_MOVE_TO_STD_NAMESPACE
85 inline void swap(_STLP_PRIV _Bit_reference& __x, _STLP_PRIV _Bit_reference& __y) {
86 bool __tmp = (bool)__x;
91 // Might not be very useful but costs nothing!
93 struct __type_traits<_STLP_PRIV _Bit_reference> {
94 typedef __false_type has_trivial_default_constructor;
95 typedef __true_type has_trivial_copy_constructor;
96 typedef __false_type has_trivial_assignment_operator;
97 typedef __true_type has_trivial_destructor;
98 typedef __false_type is_POD_type;
101 _STLP_MOVE_TO_PRIV_NAMESPACE
103 struct _Bit_iterator_base {
104 typedef ptrdiff_t difference_type;
107 unsigned int _M_offset;
110 if (_M_offset++ == _STLP_WORD_BIT - 1) {
116 void _M_bump_down() {
117 if (_M_offset-- == 0) {
118 _M_offset = _STLP_WORD_BIT - 1;
123 _Bit_iterator_base() : _M_p(0), _M_offset(0) {}
124 _Bit_iterator_base(unsigned int* __x, unsigned int __y) : _M_p(__x), _M_offset(__y) {}
125 // see comment in doc/README.evc4
126 // TODO: since this still applies to the MIPS compiler delivered with VC8,
127 // but isn't mentioned in its (yet nonexistant) README.evc8.
128 #if defined(_MSC_VER) && _MSC_VER<=1400 && defined(MIPS) && defined(NDEBUG)
129 _Bit_iterator_base( const _Bit_iterator_base& __x) : _M_p(__x._M_p), _M_offset(__x._M_offset) {}
131 // _Bit_iterator_base& operator = ( const _Bit_iterator_base& __x) { _M_p = __x._M_p ; _M_offset = __x._M_offset ; return *this; }
133 void _M_advance (difference_type __i) {
134 difference_type __n = __i + _M_offset;
135 _M_p += __n / _STLP_WORD_BIT;
136 __n = __n % _STLP_WORD_BIT;
138 _M_offset = (unsigned int) __n + _STLP_WORD_BIT;
141 _M_offset = (unsigned int) __n;
144 difference_type _M_subtract(const _Bit_iterator_base& __x) const {
145 return _STLP_WORD_BIT * (_M_p - __x._M_p) + _M_offset - __x._M_offset;
149 inline bool _STLP_CALL operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
150 return __y._M_p == __x._M_p && __y._M_offset == __x._M_offset;
152 inline bool _STLP_CALL operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
153 return __y._M_p != __x._M_p || __y._M_offset != __x._M_offset;
156 inline bool _STLP_CALL operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
157 return __x._M_p < __y._M_p || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset);
160 inline bool _STLP_CALL operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
161 return operator <(__y , __x);
163 inline bool _STLP_CALL operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
166 inline bool _STLP_CALL operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
170 template <class _Ref, class _Ptr>
171 struct _Bit_iter : public _Bit_iterator_base {
172 typedef _Ref reference;
173 typedef _Ptr pointer;
174 typedef _Bit_iter<_Ref, _Ptr> _Self;
175 typedef random_access_iterator_tag iterator_category;
176 typedef bool value_type;
177 typedef ptrdiff_t difference_type;
178 typedef size_t size_type;
180 _Bit_iter(unsigned int* __x, unsigned int __y) : _Bit_iterator_base(__x, __y) {}
183 _Bit_iter(const _Bit_iter<_Bit_reference, _Bit_reference*>& __x):
184 _Bit_iterator_base((const _Bit_iterator_base&)__x) {}
186 // _Self& operator = (const _Bit_iter<_Bit_reference, _Bit_reference*>& __x)
187 // { (_Bit_iterator_base&)*this = (const _Bit_iterator_base&)__x; return *this; }
189 reference operator*() const {
190 return _Bit_reference(_M_p, 1UL << _M_offset);
192 _Self& operator++() {
196 _Self operator++(int) {
201 _Self& operator--() {
205 _Self operator--(int) {
210 _Self& operator+=(difference_type __i) {
214 _Self& operator-=(difference_type __i) {
218 _Self operator+(difference_type __i) const {
222 _Self operator-(difference_type __i) const {
226 difference_type operator-(const _Self& __x) const {
227 return _M_subtract(__x);
229 reference operator[](difference_type __i) { return *(*this + __i); }
232 template <class _Ref, class _Ptr>
233 inline _Bit_iter<_Ref,_Ptr> _STLP_CALL
234 operator+(ptrdiff_t __n, const _Bit_iter<_Ref, _Ptr>& __x) {
238 _STLP_MOVE_TO_STD_NAMESPACE
240 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
241 template <class _Ref, class _Ptr>
242 struct __type_traits< _STLP_PRIV _Bit_iter<_Ref, _Ptr> > {
243 typedef __false_type has_trivial_default_constructor;
244 typedef __true_type has_trivial_copy_constructor;
245 typedef __true_type has_trivial_assignment_operator;
246 typedef __true_type has_trivial_destructor;
247 typedef __false_type is_POD_type;
249 #endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
251 #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
252 inline random_access_iterator_tag iterator_category(const _STLP_PRIV _Bit_iterator_base&)
253 { return random_access_iterator_tag(); }
254 inline ptrdiff_t* distance_type(const _STLP_PRIV _Bit_iterator_base&)
255 { return (ptrdiff_t*)0; }
256 inline bool* value_type(const _STLP_PRIV _Bit_iter<_STLP_PRIV _Bit_reference, _STLP_PRIV _Bit_reference*>&)
258 inline bool* value_type(const _STLP_PRIV _Bit_iter<bool, const bool*>&)
262 _STLP_MOVE_TO_PRIV_NAMESPACE
264 typedef _Bit_iter<bool, const bool*> _Bit_const_iterator;
265 typedef _Bit_iter<_Bit_reference, _Bit_reference*> _Bit_iterator;
267 // Bit-vector base class, which encapsulates the difference between
268 // old SGI-style allocators and standard-conforming allocators.
269 template <class _Alloc>
270 class _Bvector_base {
271 typedef _Bvector_base<_Alloc> _Self;
273 _STLP_FORCE_ALLOCATORS(bool, _Alloc)
274 typedef typename _Alloc_traits<bool, _Alloc>::allocator_type allocator_type;
275 typedef unsigned int __chunk_type;
276 typedef typename _Alloc_traits<__chunk_type,
277 _Alloc>::allocator_type __chunk_allocator_type;
278 allocator_type get_allocator() const {
279 return _STLP_CONVERT_ALLOCATOR((const __chunk_allocator_type&)_M_end_of_storage, bool);
281 static allocator_type __get_dfl_allocator() { return allocator_type(); }
283 _Bvector_base(const allocator_type& __a)
284 : _M_start(), _M_finish(), _M_end_of_storage(_STLP_CONVERT_ALLOCATOR(__a, __chunk_type),
287 _Bvector_base(__move_source<_Self> src)
288 : _M_start(src.get()._M_start), _M_finish(src.get()._M_finish),
289 _M_end_of_storage(src.get()._M_end_of_storage) {
290 //Make the source destroyable
291 src.get()._M_start._M_p = 0;
300 unsigned int* _M_bit_alloc(size_t __n) {
301 return _M_end_of_storage.allocate((__n + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT);
303 void _M_deallocate() {
305 _M_end_of_storage.deallocate(_M_start._M_p,
306 _M_end_of_storage._M_data - _M_start._M_p);
309 _Bit_iterator _M_start;
310 _Bit_iterator _M_finish;
311 _STLP_alloc_proxy<__chunk_type*, __chunk_type, __chunk_allocator_type> _M_end_of_storage;
315 // The next few lines are confusing. What we're doing is declaring a
316 // partial specialization of vector<T, Alloc> if we have the necessary
317 // compiler support. Otherwise, we define a class bit_vector which uses
318 // the default allocator.
320 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_BOOL) && !defined (__SUNPRO_CC)
321 # define _STLP_VECBOOL_TEMPLATE
322 # define __BVEC_TMPL_HEADER template <class _Alloc>
324 # undef _STLP_VECBOOL_TEMPLATE
325 # ifdef _STLP_NO_BOOL
326 # define __BVEC_TMPL_HEADER
328 # define __BVEC_TMPL_HEADER _STLP_TEMPLATE_NULL
330 # if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))) //*TY 12/17/2000 -
331 # define _Alloc _STLP_DEFAULT_ALLOCATOR(bool)
333 # define _Alloc allocator<bool>
337 #if defined (_STLP_DEBUG)
338 # define vector _STLP_NON_DBG_NAME(vector)
342 # define __BVECTOR_QUALIFIED bit_vector
343 # define __BVECTOR bit_vector
345 # ifdef _STLP_VECBOOL_TEMPLATE
346 # define __BVECTOR_QUALIFIED vector<bool, _Alloc>
348 # define __BVECTOR_QUALIFIED vector<bool, allocator<bool> >
350 # if defined (_STLP_PARTIAL_SPEC_NEEDS_TEMPLATE_ARGS)
351 # define __BVECTOR __BVECTOR_QUALIFIED
353 # define __BVECTOR vector
357 #if !defined (_STLP_DEBUG) || defined (_STLP_NO_BOOL)
358 _STLP_MOVE_TO_STD_NAMESPACE
362 class __BVECTOR_QUALIFIED : public _STLP_PRIV _Bvector_base<_Alloc >
363 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_DEBUG)
364 , public __stlport_class< __BVECTOR_QUALIFIED >
367 typedef _STLP_PRIV _Bvector_base<_Alloc > _Base;
368 typedef __BVECTOR_QUALIFIED _Self;
370 typedef bool value_type;
371 typedef size_t size_type;
372 typedef ptrdiff_t difference_type;
373 typedef _STLP_PRIV _Bit_reference reference;
374 typedef bool const_reference;
375 typedef _STLP_PRIV _Bit_reference* pointer;
376 typedef const bool* const_pointer;
377 typedef random_access_iterator_tag _Iterator_category;
379 typedef _STLP_PRIV _Bit_iterator iterator;
380 typedef _STLP_PRIV _Bit_const_iterator const_iterator;
382 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
384 #ifdef _STLP_VECBOOL_TEMPLATE
385 typedef typename _STLP_PRIV _Bvector_base<_Alloc >::allocator_type allocator_type;
386 typedef typename _STLP_PRIV _Bvector_base<_Alloc >::__chunk_type __chunk_type;
388 typedef _STLP_PRIV _Bvector_base<_Alloc >::allocator_type allocator_type;
389 typedef _STLP_PRIV _Bvector_base<_Alloc >::__chunk_type __chunk_type;
394 void _M_initialize(size_type __n) {
395 unsigned int* __q = this->_M_bit_alloc(__n);
396 this->_M_end_of_storage._M_data = __q + (__n + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
397 this->_M_start = iterator(__q, 0);
398 this->_M_finish = this->_M_start + difference_type(__n);
400 void _M_insert_aux(iterator __position, bool __x) {
401 if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
402 _STLP_PRIV __copy_backward(__position, this->_M_finish, this->_M_finish + 1,
403 random_access_iterator_tag(), (difference_type*)0 );
408 size_type __len = size() ? 2 * size() : _STLP_WORD_BIT;
409 unsigned int* __q = this->_M_bit_alloc(__len);
410 iterator __i = copy(begin(), __position, iterator(__q, 0));
412 this->_M_finish = copy(__position, end(), __i);
413 this->_M_deallocate();
414 this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
415 this->_M_start = iterator(__q, 0);
419 #if defined (_STLP_MEMBER_TEMPLATES)
420 template <class _InputIterator>
421 void _M_initialize_range(_InputIterator __first, _InputIterator __last,
422 const input_iterator_tag &) {
423 this->_M_start = iterator();
424 this->_M_finish = iterator();
425 this->_M_end_of_storage._M_data = 0;
426 for ( ; __first != __last; ++__first)
430 template <class _ForwardIterator>
431 void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
432 const forward_iterator_tag &) {
433 size_type __n = distance(__first, __last);
435 copy(__first, __last, this->_M_start);
438 template <class _InputIterator>
439 void _M_insert_range(iterator __pos,
440 _InputIterator __first, _InputIterator __last,
441 const input_iterator_tag &) {
442 for ( ; __first != __last; ++__first) {
443 __pos = insert(__pos, *__first);
448 template <class _ForwardIterator>
449 void _M_insert_range(iterator __position,
450 _ForwardIterator __first, _ForwardIterator __last,
451 const forward_iterator_tag &) {
452 if (__first != __last) {
453 size_type __n = distance(__first, __last);
454 if (capacity() - size() >= __n) {
455 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + difference_type(__n),
456 random_access_iterator_tag(), (difference_type*)0 );
457 copy(__first, __last, __position);
458 this->_M_finish += difference_type(__n);
461 size_type __len = size() + (max)(size(), __n);
462 unsigned int* __q = this->_M_bit_alloc(__len);
463 iterator __i = copy(begin(), __position, iterator(__q, 0));
464 __i = copy(__first, __last, __i);
465 this->_M_finish = copy(__position, end(), __i);
466 this->_M_deallocate();
467 this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
468 this->_M_start = iterator(__q, 0);
473 #endif /* _STLP_MEMBER_TEMPLATES */
476 iterator begin() { return this->_M_start; }
477 const_iterator begin() const { return this->_M_start; }
478 iterator end() { return this->_M_finish; }
479 const_iterator end() const { return this->_M_finish; }
481 reverse_iterator rbegin() { return reverse_iterator(end()); }
482 const_reverse_iterator rbegin() const {
483 return const_reverse_iterator(end());
485 reverse_iterator rend() { return reverse_iterator(begin()); }
486 const_reverse_iterator rend() const {
487 return const_reverse_iterator(begin());
490 size_type size() const { return size_type(end() - begin()); }
491 size_type max_size() const { return size_type(-1); }
492 size_type capacity() const {
493 return size_type(const_iterator(this->_M_end_of_storage._M_data, 0) - begin());
495 bool empty() const { return begin() == end(); }
496 reference operator[](size_type __n)
497 { return *(begin() + difference_type(__n)); }
498 const_reference operator[](size_type __n) const
499 { return *(begin() + difference_type(__n)); }
501 void _M_range_check(size_type __n) const {
502 if (__n >= this->size())
503 __stl_throw_range_error("vector<bool>");
506 reference at(size_type __n)
507 { _M_range_check(__n); return (*this)[__n]; }
508 const_reference at(size_type __n) const
509 { _M_range_check(__n); return (*this)[__n]; }
511 explicit __BVECTOR(const allocator_type& __a = allocator_type())
512 : _STLP_PRIV _Bvector_base<_Alloc >(__a) {}
514 __BVECTOR(size_type __n, bool __val,
515 const allocator_type& __a = allocator_type())
516 : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
518 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __val ? ~0 : 0);
521 explicit __BVECTOR(size_type __n)
522 : _STLP_PRIV _Bvector_base<_Alloc >(allocator_type()) {
524 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), 0);
527 __BVECTOR(const _Self& __x)
528 : _STLP_PRIV _Bvector_base<_Alloc >(__x.get_allocator()) {
529 _M_initialize(__x.size());
530 copy(__x.begin(), __x.end(), this->_M_start);
533 #if defined (_STLP_MEMBER_TEMPLATES)
534 template <class _Integer>
535 void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
537 fill(this->_M_start._M_p, this->_M_end_of_storage._M_data, __x ? ~0 : 0);
540 template <class _InputIterator>
541 void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
542 const __false_type&) {
543 _M_initialize_range(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
545 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
546 // Check whether it's an integral type. If so, it's not an iterator.
547 template <class _InputIterator>
548 __BVECTOR(_InputIterator __first, _InputIterator __last)
549 : _STLP_PRIV _Bvector_base<_Alloc >(allocator_type()) {
550 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
551 _M_initialize_dispatch(__first, __last, _Integral());
554 template <class _InputIterator>
555 __BVECTOR(_InputIterator __first, _InputIterator __last,
556 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
557 : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
558 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
559 _M_initialize_dispatch(__first, __last, _Integral());
561 #else /* _STLP_MEMBER_TEMPLATES */
562 __BVECTOR(const_iterator __first, const_iterator __last,
563 const allocator_type& __a = allocator_type())
564 : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
565 size_type __n = distance(__first, __last);
567 copy(__first, __last, this->_M_start);
569 __BVECTOR(const bool* __first, const bool* __last,
570 const allocator_type& __a = allocator_type())
571 : _STLP_PRIV _Bvector_base<_Alloc >(__a) {
572 size_type __n = distance(__first, __last);
574 copy(__first, __last, this->_M_start);
576 #endif /* _STLP_MEMBER_TEMPLATES */
578 __BVECTOR(__move_source<_Self> src)
579 : _STLP_PRIV _Bvector_base<_Alloc >(__move_source<_Base>(src.get())) {}
583 __BVECTOR_QUALIFIED& operator=(const __BVECTOR_QUALIFIED& __x) {
584 if (&__x == this) return *this;
585 if (__x.size() > capacity()) {
586 this->_M_deallocate();
587 _M_initialize(__x.size());
589 copy(__x.begin(), __x.end(), begin());
590 this->_M_finish = begin() + difference_type(__x.size());
594 // assign(), a generalized assignment member function. Two
595 // versions: one that takes a count, and one that takes a range.
596 // The range version is a member template, so we dispatch on whether
597 // or not the type is an integer.
599 void _M_fill_assign(size_t __n, bool __x) {
601 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
602 insert(end(), __n - size(), __x);
605 erase(begin() + __n, end());
606 fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
609 void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
611 #if defined (_STLP_MEMBER_TEMPLATES)
612 template <class _InputIterator>
613 void assign(_InputIterator __first, _InputIterator __last) {
614 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
615 _M_assign_dispatch(__first, __last, _Integral());
618 template <class _Integer>
619 void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
620 { _M_fill_assign((size_t) __n, (bool) __val); }
622 template <class _InputIter>
623 void _M_assign_dispatch(_InputIter __first, _InputIter __last, const __false_type&)
624 { _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
626 template <class _InputIterator>
627 void _M_assign_aux(_InputIterator __first, _InputIterator __last,
628 const input_iterator_tag &) {
629 iterator __cur = begin();
630 for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
632 if (__first == __last)
635 insert(end(), __first, __last);
638 template <class _ForwardIterator>
639 void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
640 const forward_iterator_tag &) {
641 size_type __len = distance(__first, __last);
643 erase(copy(__first, __last, begin()), end());
645 _ForwardIterator __mid = __first;
646 advance(__mid, size());
647 copy(__first, __mid, begin());
648 insert(end(), __mid, __last);
651 #endif /* _STLP_MEMBER_TEMPLATES */
653 void reserve(size_type __n) {
654 if (capacity() < __n) {
655 if (max_size() < __n)
656 __stl_throw_length_error("vector<bool>");
657 unsigned int* __q = this->_M_bit_alloc(__n);
658 _STLP_PRIV _Bit_iterator __z(__q, 0);
659 this->_M_finish = copy(begin(), end(), __z);
660 this->_M_deallocate();
661 this->_M_start = iterator(__q, 0);
662 this->_M_end_of_storage._M_data = __q + (__n + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
666 reference front() { return *begin(); }
667 const_reference front() const { return *begin(); }
668 reference back() { return *(end() - 1); }
669 const_reference back() const { return *(end() - 1); }
670 void push_back(bool __x) {
671 if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
672 *(this->_M_finish) = __x;
676 _M_insert_aux(end(), __x);
678 void swap(__BVECTOR_QUALIFIED& __x) {
679 _STLP_STD::swap(this->_M_start, __x._M_start);
680 _STLP_STD::swap(this->_M_finish, __x._M_finish);
681 this->_M_end_of_storage.swap(__x._M_end_of_storage);
683 iterator insert(iterator __position, bool __x = bool()) {
684 difference_type __n = __position - begin();
685 if (this->_M_finish._M_p != this->_M_end_of_storage._M_data && __position == end()) {
686 *(this->_M_finish) = __x;
690 _M_insert_aux(__position, __x);
691 return begin() + __n;
694 #if defined (_STLP_MEMBER_TEMPLATES)
696 template <class _Integer>
697 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
698 const __true_type&) {
699 _M_fill_insert(__pos, (size_type) __n, (bool) __x);
702 template <class _InputIterator>
703 void _M_insert_dispatch(iterator __pos,
704 _InputIterator __first, _InputIterator __last,
705 const __false_type&) {
706 _M_insert_range(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
709 // Check whether it's an integral type. If so, it's not an iterator.
710 template <class _InputIterator>
711 void insert(iterator __position,
712 _InputIterator __first, _InputIterator __last) {
713 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
714 _M_insert_dispatch(__position, __first, __last, _Integral());
716 #else /* _STLP_MEMBER_TEMPLATES */
717 void insert(iterator __position,
718 const_iterator __first, const_iterator __last) {
719 if (__first == __last) return;
720 size_type __n = distance(__first, __last);
721 if (capacity() - size() >= __n) {
722 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + __n,
723 random_access_iterator_tag(), (difference_type*)0 );
724 copy(__first, __last, __position);
725 this->_M_finish += __n;
728 size_type __len = size() + (max)(size(), __n);
729 unsigned int* __q = this->_M_bit_alloc(__len);
730 iterator __i = copy(begin(), __position, iterator(__q, 0));
731 __i = copy(__first, __last, __i);
732 this->_M_finish = copy(__position, end(), __i);
733 this->_M_deallocate();
734 this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
735 this->_M_start = iterator(__q, 0);
739 void insert(iterator __position, const bool* __first, const bool* __last) {
740 if (__first == __last) return;
741 size_type __n = distance(__first, __last);
742 if (capacity() - size() >= __n) {
743 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + __n,
744 random_access_iterator_tag(), (difference_type*)0 );
745 copy(__first, __last, __position);
746 this->_M_finish += __n;
749 size_type __len = size() + (max)(size(), __n);
750 unsigned int* __q = this->_M_bit_alloc(__len);
751 iterator __i = copy(begin(), __position, iterator(__q, 0));
752 __i = copy(__first, __last, __i);
753 this->_M_finish = copy(__position, end(), __i);
754 this->_M_deallocate();
755 this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
756 this->_M_start = iterator(__q, 0);
759 #endif /* _STLP_MEMBER_TEMPLATES */
761 void _M_fill_insert(iterator __position, size_type __n, bool __x) {
762 if (__n == 0) return;
763 if (capacity() - size() >= __n) {
764 _STLP_PRIV __copy_backward(__position, end(), this->_M_finish + difference_type(__n),
765 random_access_iterator_tag(), (difference_type*)0 );
766 fill(__position, __position + difference_type(__n), __x);
767 this->_M_finish += difference_type(__n);
770 size_type __len = size() + (max)(size(), __n);
771 unsigned int* __q = this->_M_bit_alloc(__len);
772 iterator __i = copy(begin(), __position, iterator(__q, 0));
773 fill_n(__i, __n, __x);
774 this->_M_finish = copy(__position, end(), __i + difference_type(__n));
775 this->_M_deallocate();
776 this->_M_end_of_storage._M_data = __q + (__len + _STLP_WORD_BIT - 1)/_STLP_WORD_BIT;
777 this->_M_start = iterator(__q, 0);
781 void insert(iterator __position, size_type __n, bool __x) {
782 _M_fill_insert(__position, __n, __x);
788 iterator erase(iterator __position) {
789 if (__position + 1 != end())
790 copy(__position + 1, end(), __position);
794 iterator erase(iterator __first, iterator __last) {
795 this->_M_finish = copy(__last, end(), __first);
798 void resize(size_type __new_size, bool __x = bool()) {
799 if (__new_size < size())
800 erase(begin() + difference_type(__new_size), end());
802 insert(end(), __new_size - size(), __x);
805 for (unsigned int* __p = this->_M_start._M_p; __p != this->_M_end_of_storage._M_data; ++__p)
809 void clear() { erase(begin(), end()); }
812 #if defined (_STLP_NO_BOOL) || defined (__HP_aCC) // fixed soon (03/17/2000)
813 # define _STLP_TEMPLATE_HEADER __BVEC_TMPL_HEADER
814 # define _STLP_TEMPLATE_CONTAINER __BVECTOR_QUALIFIED
815 # include <stl/_relops_cont.h>
816 # undef _STLP_TEMPLATE_CONTAINER
817 # undef _STLP_TEMPLATE_HEADER
820 #if defined (_STLP_DEBUG) && !defined (_STLP_NO_BOOL)
821 _STLP_MOVE_TO_STD_NAMESPACE
828 #undef _STLP_VECBOOL_TEMPLATE
830 #undef __BVECTOR_QUALIFIED
831 #undef __BVEC_TMPL_HEADER
833 #undef _STLP_WORD_BIT
835 #endif /* _STLP_INTERNAL_BVECTOR_H */