1 // vector<bool> specialization -*- C++ -*-
3 // Copyright (C) 2001-2013 Free Software Foundation, Inc.
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 3, or (at your option)
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 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
28 * Hewlett-Packard Company
30 * Permission to use, copy, modify, distribute and sell this software
31 * and its documentation for any purpose is hereby granted without fee,
32 * provided that the above copyright notice appear in all copies and
33 * that both that copyright notice and this permission notice appear
34 * in supporting documentation. Hewlett-Packard Company makes no
35 * representations about the suitability of this software for any
36 * purpose. It is provided "as is" without express or implied warranty.
39 * Copyright (c) 1996-1999
40 * Silicon Graphics Computer Systems, Inc.
42 * Permission to use, copy, modify, distribute and sell this software
43 * and its documentation for any purpose is hereby granted without fee,
44 * provided that the above copyright notice appear in all copies and
45 * that both that copyright notice and this permission notice appear
46 * in supporting documentation. Silicon Graphics makes no
47 * representations about the suitability of this software for any
48 * purpose. It is provided "as is" without express or implied warranty.
51 /** @file bits/stl_bvector.h
52 * This is an internal header file, included by other library headers.
53 * Do not attempt to use it directly. @headername{vector}
56 #ifndef _STL_BVECTOR_H
57 #define _STL_BVECTOR_H 1
59 #if __cplusplus >= 201103L
60 #include <initializer_list>
63 namespace std
_GLIBCXX_VISIBILITY(default)
65 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
67 typedef unsigned long _Bit_type
;
68 enum { _S_word_bit
= int(__CHAR_BIT__
* sizeof(_Bit_type
)) };
75 _Bit_reference(_Bit_type
* __x
, _Bit_type __y
)
76 : _M_p(__x
), _M_mask(__y
) { }
78 _Bit_reference() _GLIBCXX_NOEXCEPT
: _M_p(0), _M_mask(0) { }
80 operator bool() const _GLIBCXX_NOEXCEPT
81 { return !!(*_M_p
& _M_mask
); }
84 operator=(bool __x
) _GLIBCXX_NOEXCEPT
94 operator=(const _Bit_reference
& __x
) _GLIBCXX_NOEXCEPT
95 { return *this = bool(__x
); }
98 operator==(const _Bit_reference
& __x
) const
99 { return bool(*this) == bool(__x
); }
102 operator<(const _Bit_reference
& __x
) const
103 { return !bool(*this) && bool(__x
); }
106 flip() _GLIBCXX_NOEXCEPT
107 { *_M_p
^= _M_mask
; }
110 #if __cplusplus >= 201103L
112 swap(_Bit_reference __x
, _Bit_reference __y
) noexcept
120 swap(_Bit_reference __x
, bool& __y
) noexcept
128 swap(bool& __x
, _Bit_reference __y
) noexcept
136 struct _Bit_iterator_base
137 : public std::iterator
<std::random_access_iterator_tag
, bool>
140 unsigned int _M_offset
;
142 _Bit_iterator_base(_Bit_type
* __x
, unsigned int __y
)
143 : _M_p(__x
), _M_offset(__y
) { }
148 if (_M_offset
++ == int(_S_word_bit
) - 1)
158 if (_M_offset
-- == 0)
160 _M_offset
= int(_S_word_bit
) - 1;
166 _M_incr(ptrdiff_t __i
)
168 difference_type __n
= __i
+ _M_offset
;
169 _M_p
+= __n
/ int(_S_word_bit
);
170 __n
= __n
% int(_S_word_bit
);
173 __n
+= int(_S_word_bit
);
176 _M_offset
= static_cast<unsigned int>(__n
);
180 operator==(const _Bit_iterator_base
& __i
) const
181 { return _M_p
== __i
._M_p
&& _M_offset
== __i
._M_offset
; }
184 operator<(const _Bit_iterator_base
& __i
) const
186 return _M_p
< __i
._M_p
187 || (_M_p
== __i
._M_p
&& _M_offset
< __i
._M_offset
);
191 operator!=(const _Bit_iterator_base
& __i
) const
192 { return !(*this == __i
); }
195 operator>(const _Bit_iterator_base
& __i
) const
196 { return __i
< *this; }
199 operator<=(const _Bit_iterator_base
& __i
) const
200 { return !(__i
< *this); }
203 operator>=(const _Bit_iterator_base
& __i
) const
204 { return !(*this < __i
); }
208 operator-(const _Bit_iterator_base
& __x
, const _Bit_iterator_base
& __y
)
210 return (int(_S_word_bit
) * (__x
._M_p
- __y
._M_p
)
211 + __x
._M_offset
- __y
._M_offset
);
214 struct _Bit_iterator
: public _Bit_iterator_base
216 typedef _Bit_reference reference
;
217 typedef _Bit_reference
* pointer
;
218 typedef _Bit_iterator iterator
;
220 _Bit_iterator() : _Bit_iterator_base(0, 0) { }
222 _Bit_iterator(_Bit_type
* __x
, unsigned int __y
)
223 : _Bit_iterator_base(__x
, __y
) { }
226 _M_const_cast() const
231 { return reference(_M_p
, 1UL << _M_offset
); }
243 iterator __tmp
= *this;
258 iterator __tmp
= *this;
264 operator+=(difference_type __i
)
271 operator-=(difference_type __i
)
278 operator+(difference_type __i
) const
280 iterator __tmp
= *this;
285 operator-(difference_type __i
) const
287 iterator __tmp
= *this;
292 operator[](difference_type __i
) const
293 { return *(*this + __i
); }
297 operator+(ptrdiff_t __n
, const _Bit_iterator
& __x
)
298 { return __x
+ __n
; }
300 struct _Bit_const_iterator
: public _Bit_iterator_base
302 typedef bool reference
;
303 typedef bool const_reference
;
304 typedef const bool* pointer
;
305 typedef _Bit_const_iterator const_iterator
;
307 _Bit_const_iterator() : _Bit_iterator_base(0, 0) { }
309 _Bit_const_iterator(_Bit_type
* __x
, unsigned int __y
)
310 : _Bit_iterator_base(__x
, __y
) { }
312 _Bit_const_iterator(const _Bit_iterator
& __x
)
313 : _Bit_iterator_base(__x
._M_p
, __x
._M_offset
) { }
316 _M_const_cast() const
317 { return _Bit_iterator(_M_p
, _M_offset
); }
321 { return _Bit_reference(_M_p
, 1UL << _M_offset
); }
333 const_iterator __tmp
= *this;
348 const_iterator __tmp
= *this;
354 operator+=(difference_type __i
)
361 operator-=(difference_type __i
)
368 operator+(difference_type __i
) const
370 const_iterator __tmp
= *this;
375 operator-(difference_type __i
) const
377 const_iterator __tmp
= *this;
382 operator[](difference_type __i
) const
383 { return *(*this + __i
); }
386 inline _Bit_const_iterator
387 operator+(ptrdiff_t __n
, const _Bit_const_iterator
& __x
)
388 { return __x
+ __n
; }
391 __fill_bvector(_Bit_iterator __first
, _Bit_iterator __last
, bool __x
)
393 for (; __first
!= __last
; ++__first
)
398 fill(_Bit_iterator __first
, _Bit_iterator __last
, const bool& __x
)
400 if (__first
._M_p
!= __last
._M_p
)
402 std::fill(__first
._M_p
+ 1, __last
._M_p
, __x
? ~0 : 0);
403 __fill_bvector(__first
, _Bit_iterator(__first
._M_p
+ 1, 0), __x
);
404 __fill_bvector(_Bit_iterator(__last
._M_p
, 0), __last
, __x
);
407 __fill_bvector(__first
, __last
, __x
);
410 template<typename _Alloc
>
413 typedef typename
_Alloc::template rebind
<_Bit_type
>::other
417 : public _Bit_alloc_type
419 _Bit_iterator _M_start
;
420 _Bit_iterator _M_finish
;
421 _Bit_type
* _M_end_of_storage
;
424 : _Bit_alloc_type(), _M_start(), _M_finish(), _M_end_of_storage(0)
427 _Bvector_impl(const _Bit_alloc_type
& __a
)
428 : _Bit_alloc_type(__a
), _M_start(), _M_finish(), _M_end_of_storage(0)
431 #if __cplusplus >= 201103L
432 _Bvector_impl(_Bit_alloc_type
&& __a
)
433 : _Bit_alloc_type(std::move(__a
)), _M_start(), _M_finish(),
440 typedef _Alloc allocator_type
;
443 _M_get_Bit_allocator() _GLIBCXX_NOEXCEPT
444 { return *static_cast<_Bit_alloc_type
*>(&this->_M_impl
); }
446 const _Bit_alloc_type
&
447 _M_get_Bit_allocator() const _GLIBCXX_NOEXCEPT
448 { return *static_cast<const _Bit_alloc_type
*>(&this->_M_impl
); }
451 get_allocator() const _GLIBCXX_NOEXCEPT
452 { return allocator_type(_M_get_Bit_allocator()); }
457 _Bvector_base(const allocator_type
& __a
)
460 #if __cplusplus >= 201103L
461 _Bvector_base(_Bvector_base
&& __x
) noexcept
462 : _M_impl(std::move(__x
._M_get_Bit_allocator()))
464 this->_M_impl
._M_start
= __x
._M_impl
._M_start
;
465 this->_M_impl
._M_finish
= __x
._M_impl
._M_finish
;
466 this->_M_impl
._M_end_of_storage
= __x
._M_impl
._M_end_of_storage
;
467 __x
._M_impl
._M_start
= _Bit_iterator();
468 __x
._M_impl
._M_finish
= _Bit_iterator();
469 __x
._M_impl
._M_end_of_storage
= 0;
474 { this->_M_deallocate(); }
477 _Bvector_impl _M_impl
;
480 _M_allocate(size_t __n
)
481 { return _M_impl
.allocate(_S_nword(__n
)); }
486 if (_M_impl
._M_start
._M_p
)
487 _M_impl
.deallocate(_M_impl
._M_start
._M_p
,
488 _M_impl
._M_end_of_storage
- _M_impl
._M_start
._M_p
);
493 { return (__n
+ int(_S_word_bit
) - 1) / int(_S_word_bit
); }
496 _GLIBCXX_END_NAMESPACE_CONTAINER
499 // Declare a partial specialization of vector<T, Alloc>.
500 #include <bits/stl_vector.h>
502 namespace std
_GLIBCXX_VISIBILITY(default)
504 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
507 * @brief A specialization of vector for booleans which offers fixed time
508 * access to individual elements in any order.
512 * @tparam _Alloc Allocator type.
514 * Note that vector<bool> does not actually meet the requirements for being
515 * a container. This is because the reference and pointer types are not
516 * really references and pointers to bool. See DR96 for details. @see
517 * vector for function documentation.
519 * In some terminology a %vector can be described as a dynamic
520 * C-style array, it offers fast and efficient access to individual
521 * elements in any order and saves the user from worrying about
522 * memory and size allocation. Subscripting ( @c [] ) access is
523 * also provided as with C-style arrays.
525 template<typename _Alloc
>
526 class vector
<bool, _Alloc
> : protected _Bvector_base
<_Alloc
>
528 typedef _Bvector_base
<_Alloc
> _Base
;
530 #if __cplusplus >= 201103L
531 template<typename
> friend class hash
;
535 typedef bool value_type
;
536 typedef size_t size_type
;
537 typedef ptrdiff_t difference_type
;
538 typedef _Bit_reference reference
;
539 typedef bool const_reference
;
540 typedef _Bit_reference
* pointer
;
541 typedef const bool* const_pointer
;
542 typedef _Bit_iterator iterator
;
543 typedef _Bit_const_iterator const_iterator
;
544 typedef std::reverse_iterator
<const_iterator
> const_reverse_iterator
;
545 typedef std::reverse_iterator
<iterator
> reverse_iterator
;
546 typedef _Alloc allocator_type
;
548 allocator_type
get_allocator() const
549 { return _Base::get_allocator(); }
552 using _Base::_M_allocate
;
553 using _Base::_M_deallocate
;
554 using _Base::_S_nword
;
555 using _Base::_M_get_Bit_allocator
;
562 vector(const allocator_type
& __a
)
565 #if __cplusplus >= 201103L
567 vector(size_type __n
, const allocator_type
& __a
= allocator_type())
568 : vector(__n
, false, __a
)
571 vector(size_type __n
, const bool& __value
,
572 const allocator_type
& __a
= allocator_type())
576 std::fill(this->_M_impl
._M_start
._M_p
, this->_M_impl
._M_end_of_storage
,
581 vector(size_type __n
, const bool& __value
= bool(),
582 const allocator_type
& __a
= allocator_type())
586 std::fill(this->_M_impl
._M_start
._M_p
, this->_M_impl
._M_end_of_storage
,
591 vector(const vector
& __x
)
592 : _Base(__x
._M_get_Bit_allocator())
594 _M_initialize(__x
.size());
595 _M_copy_aligned(__x
.begin(), __x
.end(), this->_M_impl
._M_start
);
598 #if __cplusplus >= 201103L
599 vector(vector
&& __x
) noexcept
600 : _Base(std::move(__x
)) { }
602 vector(initializer_list
<bool> __l
,
603 const allocator_type
& __a
= allocator_type())
606 _M_initialize_range(__l
.begin(), __l
.end(),
607 random_access_iterator_tag());
611 #if __cplusplus >= 201103L
612 template<typename _InputIterator
,
613 typename
= std::_RequireInputIter
<_InputIterator
>>
614 vector(_InputIterator __first
, _InputIterator __last
,
615 const allocator_type
& __a
= allocator_type())
617 { _M_initialize_dispatch(__first
, __last
, __false_type()); }
619 template<typename _InputIterator
>
620 vector(_InputIterator __first
, _InputIterator __last
,
621 const allocator_type
& __a
= allocator_type())
624 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
625 _M_initialize_dispatch(__first
, __last
, _Integral());
629 ~vector() _GLIBCXX_NOEXCEPT
{ }
632 operator=(const vector
& __x
)
636 if (__x
.size() > capacity())
638 this->_M_deallocate();
639 _M_initialize(__x
.size());
641 this->_M_impl
._M_finish
= _M_copy_aligned(__x
.begin(), __x
.end(),
646 #if __cplusplus >= 201103L
648 operator=(vector
&& __x
)
658 operator=(initializer_list
<bool> __l
)
660 this->assign (__l
.begin(), __l
.end());
665 // assign(), a generalized assignment member function. Two
666 // versions: one that takes a count, and one that takes a range.
667 // The range version is a member template, so we dispatch on whether
668 // or not the type is an integer.
670 assign(size_type __n
, const bool& __x
)
671 { _M_fill_assign(__n
, __x
); }
673 #if __cplusplus >= 201103L
674 template<typename _InputIterator
,
675 typename
= std::_RequireInputIter
<_InputIterator
>>
677 assign(_InputIterator __first
, _InputIterator __last
)
678 { _M_assign_dispatch(__first
, __last
, __false_type()); }
680 template<typename _InputIterator
>
682 assign(_InputIterator __first
, _InputIterator __last
)
684 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
685 _M_assign_dispatch(__first
, __last
, _Integral());
689 #if __cplusplus >= 201103L
691 assign(initializer_list
<bool> __l
)
692 { this->assign(__l
.begin(), __l
.end()); }
696 begin() _GLIBCXX_NOEXCEPT
697 { return this->_M_impl
._M_start
; }
700 begin() const _GLIBCXX_NOEXCEPT
701 { return this->_M_impl
._M_start
; }
704 end() _GLIBCXX_NOEXCEPT
705 { return this->_M_impl
._M_finish
; }
708 end() const _GLIBCXX_NOEXCEPT
709 { return this->_M_impl
._M_finish
; }
712 rbegin() _GLIBCXX_NOEXCEPT
713 { return reverse_iterator(end()); }
715 const_reverse_iterator
716 rbegin() const _GLIBCXX_NOEXCEPT
717 { return const_reverse_iterator(end()); }
720 rend() _GLIBCXX_NOEXCEPT
721 { return reverse_iterator(begin()); }
723 const_reverse_iterator
724 rend() const _GLIBCXX_NOEXCEPT
725 { return const_reverse_iterator(begin()); }
727 #if __cplusplus >= 201103L
729 cbegin() const noexcept
730 { return this->_M_impl
._M_start
; }
733 cend() const noexcept
734 { return this->_M_impl
._M_finish
; }
736 const_reverse_iterator
737 crbegin() const noexcept
738 { return const_reverse_iterator(end()); }
740 const_reverse_iterator
741 crend() const noexcept
742 { return const_reverse_iterator(begin()); }
746 size() const _GLIBCXX_NOEXCEPT
747 { return size_type(end() - begin()); }
750 max_size() const _GLIBCXX_NOEXCEPT
752 const size_type __isize
=
753 __gnu_cxx::__numeric_traits
<difference_type
>::__max
754 - int(_S_word_bit
) + 1;
755 const size_type __asize
= _M_get_Bit_allocator().max_size();
756 return (__asize
<= __isize
/ int(_S_word_bit
)
757 ? __asize
* int(_S_word_bit
) : __isize
);
761 capacity() const _GLIBCXX_NOEXCEPT
762 { return size_type(const_iterator(this->_M_impl
._M_end_of_storage
, 0)
766 empty() const _GLIBCXX_NOEXCEPT
767 { return begin() == end(); }
770 operator[](size_type __n
)
772 return *iterator(this->_M_impl
._M_start
._M_p
773 + __n
/ int(_S_word_bit
), __n
% int(_S_word_bit
));
777 operator[](size_type __n
) const
779 return *const_iterator(this->_M_impl
._M_start
._M_p
780 + __n
/ int(_S_word_bit
), __n
% int(_S_word_bit
));
785 _M_range_check(size_type __n
) const
787 if (__n
>= this->size())
788 __throw_out_of_range(__N("vector<bool>::_M_range_check"));
794 { _M_range_check(__n
); return (*this)[__n
]; }
797 at(size_type __n
) const
798 { _M_range_check(__n
); return (*this)[__n
]; }
801 reserve(size_type __n
)
803 if (__n
> max_size())
804 __throw_length_error(__N("vector::reserve"));
805 if (capacity() < __n
)
819 { return *(end() - 1); }
823 { return *(end() - 1); }
825 // _GLIBCXX_RESOLVE_LIB_DEFECTS
826 // DR 464. Suggestion for new member functions in standard containers.
827 // N.B. DR 464 says nothing about vector<bool> but we need something
828 // here due to the way we are implementing DR 464 in the debug-mode
831 data() _GLIBCXX_NOEXCEPT
{ }
836 if (this->_M_impl
._M_finish
._M_p
!= this->_M_impl
._M_end_of_storage
)
837 *this->_M_impl
._M_finish
++ = __x
;
839 _M_insert_aux(end(), __x
);
845 std::swap(this->_M_impl
._M_start
, __x
._M_impl
._M_start
);
846 std::swap(this->_M_impl
._M_finish
, __x
._M_impl
._M_finish
);
847 std::swap(this->_M_impl
._M_end_of_storage
,
848 __x
._M_impl
._M_end_of_storage
);
850 // _GLIBCXX_RESOLVE_LIB_DEFECTS
851 // 431. Swapping containers with unequal allocators.
852 std::__alloc_swap
<typename
_Base::_Bit_alloc_type
>::
853 _S_do_it(_M_get_Bit_allocator(), __x
._M_get_Bit_allocator());
856 // [23.2.5]/1, third-to-last entry in synopsis listing
858 swap(reference __x
, reference __y
) _GLIBCXX_NOEXCEPT
866 #if __cplusplus >= 201103L
867 insert(const_iterator __position
, const bool& __x
= bool())
869 insert(iterator __position
, const bool& __x
= bool())
872 const difference_type __n
= __position
- begin();
873 if (this->_M_impl
._M_finish
._M_p
!= this->_M_impl
._M_end_of_storage
874 && __position
== end())
875 *this->_M_impl
._M_finish
++ = __x
;
877 _M_insert_aux(__position
._M_const_cast(), __x
);
878 return begin() + __n
;
881 #if __cplusplus >= 201103L
882 template<typename _InputIterator
,
883 typename
= std::_RequireInputIter
<_InputIterator
>>
885 insert(iterator __position
,
886 _InputIterator __first
, _InputIterator __last
)
887 { _M_insert_dispatch(__position
, __first
, __last
, __false_type()); }
889 template<typename _InputIterator
>
891 insert(iterator __position
,
892 _InputIterator __first
, _InputIterator __last
)
894 typedef typename
std::__is_integer
<_InputIterator
>::__type _Integral
;
895 _M_insert_dispatch(__position
, __first
, __last
, _Integral());
900 insert(iterator __position
, size_type __n
, const bool& __x
)
901 { _M_fill_insert(__position
, __n
, __x
); }
903 #if __cplusplus >= 201103L
904 void insert(iterator __p
, initializer_list
<bool> __l
)
905 { this->insert(__p
, __l
.begin(), __l
.end()); }
910 { --this->_M_impl
._M_finish
; }
913 #if __cplusplus >= 201103L
914 erase(const_iterator __position
)
916 erase(iterator __position
)
918 { return _M_erase(__position
._M_const_cast()); }
921 #if __cplusplus >= 201103L
922 erase(const_iterator __first
, const_iterator __last
)
924 erase(iterator __first
, iterator __last
)
926 { return _M_erase(__first
._M_const_cast(), __last
._M_const_cast()); }
929 resize(size_type __new_size
, bool __x
= bool())
931 if (__new_size
< size())
932 _M_erase_at_end(begin() + difference_type(__new_size
));
934 insert(end(), __new_size
- size(), __x
);
937 #if __cplusplus >= 201103L
940 { _M_shrink_to_fit(); }
944 flip() _GLIBCXX_NOEXCEPT
946 for (_Bit_type
* __p
= this->_M_impl
._M_start
._M_p
;
947 __p
!= this->_M_impl
._M_end_of_storage
; ++__p
)
952 clear() _GLIBCXX_NOEXCEPT
953 { _M_erase_at_end(begin()); }
957 // Precondition: __first._M_offset == 0 && __result._M_offset == 0.
959 _M_copy_aligned(const_iterator __first
, const_iterator __last
,
962 _Bit_type
* __q
= std::copy(__first
._M_p
, __last
._M_p
, __result
._M_p
);
963 return std::copy(const_iterator(__last
._M_p
, 0), __last
,
968 _M_initialize(size_type __n
)
970 _Bit_type
* __q
= this->_M_allocate(__n
);
971 this->_M_impl
._M_end_of_storage
= __q
+ _S_nword(__n
);
972 this->_M_impl
._M_start
= iterator(__q
, 0);
973 this->_M_impl
._M_finish
= this->_M_impl
._M_start
+ difference_type(__n
);
977 _M_reallocate(size_type __n
);
979 #if __cplusplus >= 201103L
984 // Check whether it's an integral type. If so, it's not an iterator.
986 // _GLIBCXX_RESOLVE_LIB_DEFECTS
987 // 438. Ambiguity in the "do the right thing" clause
988 template<typename _Integer
>
990 _M_initialize_dispatch(_Integer __n
, _Integer __x
, __true_type
)
992 _M_initialize(static_cast<size_type
>(__n
));
993 std::fill(this->_M_impl
._M_start
._M_p
,
994 this->_M_impl
._M_end_of_storage
, __x
? ~0 : 0);
997 template<typename _InputIterator
>
999 _M_initialize_dispatch(_InputIterator __first
, _InputIterator __last
,
1001 { _M_initialize_range(__first
, __last
,
1002 std::__iterator_category(__first
)); }
1004 template<typename _InputIterator
>
1006 _M_initialize_range(_InputIterator __first
, _InputIterator __last
,
1007 std::input_iterator_tag
)
1009 for (; __first
!= __last
; ++__first
)
1010 push_back(*__first
);
1013 template<typename _ForwardIterator
>
1015 _M_initialize_range(_ForwardIterator __first
, _ForwardIterator __last
,
1016 std::forward_iterator_tag
)
1018 const size_type __n
= std::distance(__first
, __last
);
1020 std::copy(__first
, __last
, this->_M_impl
._M_start
);
1023 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1024 // 438. Ambiguity in the "do the right thing" clause
1025 template<typename _Integer
>
1027 _M_assign_dispatch(_Integer __n
, _Integer __val
, __true_type
)
1028 { _M_fill_assign(__n
, __val
); }
1030 template<class _InputIterator
>
1032 _M_assign_dispatch(_InputIterator __first
, _InputIterator __last
,
1034 { _M_assign_aux(__first
, __last
, std::__iterator_category(__first
)); }
1037 _M_fill_assign(size_t __n
, bool __x
)
1041 std::fill(this->_M_impl
._M_start
._M_p
,
1042 this->_M_impl
._M_end_of_storage
, __x
? ~0 : 0);
1043 insert(end(), __n
- size(), __x
);
1047 _M_erase_at_end(begin() + __n
);
1048 std::fill(this->_M_impl
._M_start
._M_p
,
1049 this->_M_impl
._M_end_of_storage
, __x
? ~0 : 0);
1053 template<typename _InputIterator
>
1055 _M_assign_aux(_InputIterator __first
, _InputIterator __last
,
1056 std::input_iterator_tag
)
1058 iterator __cur
= begin();
1059 for (; __first
!= __last
&& __cur
!= end(); ++__cur
, ++__first
)
1061 if (__first
== __last
)
1062 _M_erase_at_end(__cur
);
1064 insert(end(), __first
, __last
);
1067 template<typename _ForwardIterator
>
1069 _M_assign_aux(_ForwardIterator __first
, _ForwardIterator __last
,
1070 std::forward_iterator_tag
)
1072 const size_type __len
= std::distance(__first
, __last
);
1074 _M_erase_at_end(std::copy(__first
, __last
, begin()));
1077 _ForwardIterator __mid
= __first
;
1078 std::advance(__mid
, size());
1079 std::copy(__first
, __mid
, begin());
1080 insert(end(), __mid
, __last
);
1084 // Check whether it's an integral type. If so, it's not an iterator.
1086 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1087 // 438. Ambiguity in the "do the right thing" clause
1088 template<typename _Integer
>
1090 _M_insert_dispatch(iterator __pos
, _Integer __n
, _Integer __x
,
1092 { _M_fill_insert(__pos
, __n
, __x
); }
1094 template<typename _InputIterator
>
1096 _M_insert_dispatch(iterator __pos
,
1097 _InputIterator __first
, _InputIterator __last
,
1099 { _M_insert_range(__pos
, __first
, __last
,
1100 std::__iterator_category(__first
)); }
1103 _M_fill_insert(iterator __position
, size_type __n
, bool __x
);
1105 template<typename _InputIterator
>
1107 _M_insert_range(iterator __pos
, _InputIterator __first
,
1108 _InputIterator __last
, std::input_iterator_tag
)
1110 for (; __first
!= __last
; ++__first
)
1112 __pos
= insert(__pos
, *__first
);
1117 template<typename _ForwardIterator
>
1119 _M_insert_range(iterator __position
, _ForwardIterator __first
,
1120 _ForwardIterator __last
, std::forward_iterator_tag
);
1123 _M_insert_aux(iterator __position
, bool __x
);
1126 _M_check_len(size_type __n
, const char* __s
) const
1128 if (max_size() - size() < __n
)
1129 __throw_length_error(__N(__s
));
1131 const size_type __len
= size() + std::max(size(), __n
);
1132 return (__len
< size() || __len
> max_size()) ? max_size() : __len
;
1136 _M_erase_at_end(iterator __pos
)
1137 { this->_M_impl
._M_finish
= __pos
; }
1140 _M_erase(iterator __pos
);
1143 _M_erase(iterator __first
, iterator __last
);
1146 _GLIBCXX_END_NAMESPACE_CONTAINER
1149 #if __cplusplus >= 201103L
1151 #include <bits/functional_hash.h>
1153 namespace std
_GLIBCXX_VISIBILITY(default)
1155 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1158 /// std::hash specialization for vector<bool>.
1159 template<typename _Alloc
>
1160 struct hash
<_GLIBCXX_STD_C::vector
<bool, _Alloc
>>
1161 : public __hash_base
<size_t, _GLIBCXX_STD_C::vector
<bool, _Alloc
>>
1164 operator()(const _GLIBCXX_STD_C::vector
<bool, _Alloc
>&) const noexcept
;
1167 _GLIBCXX_END_NAMESPACE_VERSION