597 class vector<bool, _Alloc> :
protected _Bvector_base<_Alloc>
599 typedef _Bvector_base<_Alloc> _Base;
600 typedef typename _Base::_Bit_pointer _Bit_pointer;
601 typedef typename _Base::_Bit_alloc_traits _Bit_alloc_traits;
603#if __cplusplus >= 201103L
608 typedef bool value_type;
609 typedef size_t size_type;
610 typedef ptrdiff_t difference_type;
611 typedef _Bit_reference reference;
612 typedef bool const_reference;
613 typedef _Bit_reference* pointer;
614 typedef const bool* const_pointer;
615 typedef _Bit_iterator iterator;
616 typedef _Bit_const_iterator const_iterator;
619 typedef _Alloc allocator_type;
623 {
return _Base::get_allocator(); }
626 using _Base::_M_allocate;
627 using _Base::_M_deallocate;
628 using _Base::_S_nword;
629 using _Base::_M_get_Bit_allocator;
632#if __cplusplus >= 201103L
639 vector(
const allocator_type& __a)
642#if __cplusplus >= 201103L
644 vector(size_type __n,
const allocator_type& __a = allocator_type())
648 vector(size_type __n,
const bool& __value,
649 const allocator_type& __a = allocator_type())
652 vector(size_type __n,
const bool& __value =
bool(),
653 const allocator_type& __a = allocator_type())
657 _M_check_and_initialize(__n);
658 _M_initialize_value(__value);
662 : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator()))
664 _M_initialize(__x.
size());
665 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
668#if __cplusplus >= 201103L
669 vector(vector&&) =
default;
683 _M_initialize(__x.
size());
684 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
690 vector(vector&& __x,
const allocator_type& __a)
691 noexcept(_Bit_alloc_traits::_S_always_equal())
696 vector(
const vector& __x,
const allocator_type& __a)
699 _M_initialize(__x.
size());
700 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
704 const allocator_type& __a = allocator_type())
707 _M_initialize_range(__l.begin(), __l.end(),
712#if __cplusplus >= 201103L
713 template<
typename _InputIterator,
714 typename = std::_RequireInputIter<_InputIterator>>
715 vector(_InputIterator __first, _InputIterator __last,
716 const allocator_type& __a = allocator_type())
719 _M_initialize_range(__first, __last,
723 template<
typename _InputIterator>
724 vector(_InputIterator __first, _InputIterator __last,
725 const allocator_type& __a = allocator_type())
729 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
730 _M_initialize_dispatch(__first, __last, _Integral());
734 ~vector() _GLIBCXX_NOEXCEPT { }
741#if __cplusplus >= 201103L
742 if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
744 if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
746 this->_M_deallocate();
747 std::__alloc_on_copy(_M_get_Bit_allocator(),
748 __x._M_get_Bit_allocator());
749 _M_initialize(__x.
size());
752 std::__alloc_on_copy(_M_get_Bit_allocator(),
753 __x._M_get_Bit_allocator());
756 if (__x.
size() > capacity())
758 this->_M_deallocate();
759 _M_initialize(__x.
size());
761 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
766#if __cplusplus >= 201103L
768 operator=(vector&& __x)
noexcept(_Bit_alloc_traits::_S_nothrow_move())
770 if (_Bit_alloc_traits::_S_propagate_on_move_assign()
771 || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
773 this->_M_deallocate();
775 std::__alloc_on_move(_M_get_Bit_allocator(),
776 __x._M_get_Bit_allocator());
780 if (__x.
size() > capacity())
782 this->_M_deallocate();
783 _M_initialize(__x.
size());
785 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
795 this->
assign(__l.begin(), __l.end());
805 assign(size_type __n,
const bool& __x)
806 { _M_fill_assign(__n, __x); }
808#if __cplusplus >= 201103L
809 template<
typename _InputIterator,
810 typename = std::_RequireInputIter<_InputIterator>>
812 assign(_InputIterator __first, _InputIterator __last)
815 template<
typename _InputIterator>
817 assign(_InputIterator __first, _InputIterator __last)
820 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
821 _M_assign_dispatch(__first, __last, _Integral());
825#if __cplusplus >= 201103L
832 begin() _GLIBCXX_NOEXCEPT
833 {
return iterator(this->_M_impl._M_start._M_p, 0); }
836 begin()
const _GLIBCXX_NOEXCEPT
837 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
840 end() _GLIBCXX_NOEXCEPT
841 {
return this->_M_impl._M_finish; }
844 end()
const _GLIBCXX_NOEXCEPT
845 {
return this->_M_impl._M_finish; }
848 rbegin() _GLIBCXX_NOEXCEPT
849 {
return reverse_iterator(
end()); }
851 const_reverse_iterator
852 rbegin()
const _GLIBCXX_NOEXCEPT
853 {
return const_reverse_iterator(
end()); }
856 rend() _GLIBCXX_NOEXCEPT
857 {
return reverse_iterator(
begin()); }
859 const_reverse_iterator
860 rend()
const _GLIBCXX_NOEXCEPT
861 {
return const_reverse_iterator(
begin()); }
863#if __cplusplus >= 201103L
866 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
869 cend()
const noexcept
870 {
return this->_M_impl._M_finish; }
872 const_reverse_iterator
874 {
return const_reverse_iterator(
end()); }
876 const_reverse_iterator
877 crend()
const noexcept
878 {
return const_reverse_iterator(
begin()); }
882 size()
const _GLIBCXX_NOEXCEPT
883 {
return size_type(
end() -
begin()); }
888 const size_type __isize =
889 __gnu_cxx::__numeric_traits<difference_type>::__max
890 - int(_S_word_bit) + 1;
891 const size_type __asize
893 return (__asize <= __isize /
int(_S_word_bit)
894 ? __asize *
int(_S_word_bit) : __isize);
899 {
return size_type(const_iterator(this->_M_impl._M_end_addr(), 0)
902 _GLIBCXX_NODISCARD
bool
903 empty()
const _GLIBCXX_NOEXCEPT
908 {
return begin()[__n]; }
912 {
return begin()[__n]; }
918 if (__n >= this->
size())
919 __throw_out_of_range_fmt(__N(
"vector<bool>::_M_range_check: __n "
920 "(which is %zu) >= this->size() "
931 at(size_type __n)
const
938 __throw_length_error(__N(
"vector::reserve"));
953 {
return *(
end() - 1); }
957 {
return *(
end() - 1); }
965 data() _GLIBCXX_NOEXCEPT { }
970 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
971 *this->_M_impl._M_finish++ = __x;
973 _M_insert_aux(
end(), __x);
977 swap(vector& __x) _GLIBCXX_NOEXCEPT
979#if __cplusplus >= 201103L
980 __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value
981 || _M_get_Bit_allocator() == __x._M_get_Bit_allocator());
983 this->_M_impl._M_swap_data(__x._M_impl);
984 _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(),
985 __x._M_get_Bit_allocator());
990 swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT
998#if __cplusplus >= 201103L
999 insert(const_iterator __position,
const bool& __x =
bool())
1001 insert(iterator __position,
const bool& __x =
bool())
1004 const difference_type __n = __position -
begin();
1005 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()
1006 && __position == end())
1007 *this->_M_impl._M_finish++ = __x;
1009 _M_insert_aux(__position._M_const_cast(), __x);
1010 return begin() + __n;
1013#if __cplusplus >= 201103L
1014 template<
typename _InputIterator,
1015 typename = std::_RequireInputIter<_InputIterator>>
1017 insert(const_iterator __position,
1018 _InputIterator __first, _InputIterator __last)
1020 difference_type __offset = __position -
cbegin();
1021 _M_insert_range(__position._M_const_cast(),
1024 return begin() + __offset;
1027 template<
typename _InputIterator>
1029 insert(iterator __position,
1030 _InputIterator __first, _InputIterator __last)
1033 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1034 _M_insert_dispatch(__position, __first, __last, _Integral());
1038#if __cplusplus >= 201103L
1040 insert(const_iterator __position, size_type __n,
const bool& __x)
1042 difference_type __offset = __position -
cbegin();
1043 _M_fill_insert(__position._M_const_cast(), __n, __x);
1044 return begin() + __offset;
1048 insert(iterator __position, size_type __n,
const bool& __x)
1049 { _M_fill_insert(__position, __n, __x); }
1052#if __cplusplus >= 201103L
1055 {
return this->
insert(__p, __l.begin(), __l.end()); }
1060 { --this->_M_impl._M_finish; }
1063#if __cplusplus >= 201103L
1064 erase(const_iterator __position)
1066 erase(iterator __position)
1068 {
return _M_erase(__position._M_const_cast()); }
1071#if __cplusplus >= 201103L
1072 erase(const_iterator __first, const_iterator __last)
1074 erase(iterator __first, iterator __last)
1076 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1079 resize(size_type __new_size,
bool __x =
bool())
1081 if (__new_size <
size())
1082 _M_erase_at_end(
begin() + difference_type(__new_size));
1087#if __cplusplus >= 201103L
1090 { _M_shrink_to_fit(); }
1094 flip() _GLIBCXX_NOEXCEPT
1096 _Bit_type *
const __end = this->_M_impl._M_end_addr();
1097 for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p)
1102 clear() _GLIBCXX_NOEXCEPT
1103 { _M_erase_at_end(
begin()); }
1105#if __cplusplus >= 201103L
1106 template<
typename... _Args>
1107#if __cplusplus > 201402L
1112 emplace_back(_Args&&... __args)
1115#if __cplusplus > 201402L
1120 template<
typename... _Args>
1122 emplace(const_iterator __pos, _Args&&... __args)
1123 {
return insert(__pos,
bool(__args...)); }
1129 _M_copy_aligned(const_iterator __first, const_iterator __last,
1132 _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
1133 return std::copy(const_iterator(__last._M_p, 0), __last,
1138 _M_initialize(size_type __n)
1141 _GLIBCXX_DEBUG_ASSERT(__n <= (
size_t)-_S_word_bit);
1145 _Bit_pointer __q = this->_M_allocate(__n);
1146 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1148 this->_M_impl._M_start = __start;
1149 this->_M_impl._M_finish = __start + difference_type(__n);
1153 template<
typename _SizeT>
1155 _M_check_and_initialize(_SizeT __n)
1158 __throw_length_error(
1159 __N(
"Cannot create std::vector<bool> larger than max_size()"));
1160 _M_initialize(
static_cast<size_type
>(__n));
1164 _M_initialize_value(
bool __x)
1166 if (_Bit_type* __p = this->_M_impl._M_start._M_p)
1167 __builtin_memset(__p, __x ? ~0 : 0,
1168 (this->_M_impl._M_end_addr() - __p)
1169 *
sizeof(_Bit_type));
1173 _M_reallocate(size_type __n);
1175#if __cplusplus >= 201103L
1180#if __cplusplus < 201103L
1183 template<
typename _Integer>
1185 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1187 _M_check_and_initialize(
static_cast<size_type
>(__n));
1188 _M_initialize_value(__x);
1191 template<
typename _InputIterator>
1193 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1195 { _M_initialize_range(__first, __last,
1199 template<
typename _InputIterator>
1201 _M_initialize_range(_InputIterator __first, _InputIterator __last,
1204 for (; __first != __last; ++__first)
1208 template<
typename _ForwardIterator>
1210 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
1214 std::copy(__first, __last,
begin());
1217#if __cplusplus < 201103L
1220 template<
typename _Integer>
1222 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1223 { _M_fill_assign(__n, __val); }
1225 template<
class _InputIterator>
1227 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1233 _M_fill_assign(
size_t __n,
bool __x)
1237 _M_initialize_value(__x);
1242 _M_erase_at_end(
begin() + __n);
1243 _M_initialize_value(__x);
1247 template<
typename _InputIterator>
1249 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1252 iterator __cur =
begin();
1253 for (; __first != __last && __cur !=
end(); ++__cur, (void)++__first)
1255 if (__first == __last)
1256 _M_erase_at_end(__cur);
1261 template<
typename _ForwardIterator>
1263 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1268 _M_erase_at_end(std::copy(__first, __last,
begin()));
1271 _ForwardIterator __mid = __first;
1273 std::copy(__first, __mid,
begin());
1278#if __cplusplus < 201103L
1281 template<
typename _Integer>
1283 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
1285 { _M_fill_insert(__pos, __n, __x); }
1287 template<
typename _InputIterator>
1289 _M_insert_dispatch(iterator __pos,
1290 _InputIterator __first, _InputIterator __last,
1292 { _M_insert_range(__pos, __first, __last,
1297 _M_fill_insert(iterator __position, size_type __n,
bool __x);
1299 template<
typename _InputIterator>
1301 _M_insert_range(iterator __pos, _InputIterator __first,
1304 for (; __first != __last; ++__first)
1306 __pos =
insert(__pos, *__first);
1311 template<
typename _ForwardIterator>
1313 _M_insert_range(iterator __position, _ForwardIterator __first,
1317 _M_insert_aux(iterator __position,
bool __x);
1320 _M_check_len(size_type __n,
const char* __s)
const
1323 __throw_length_error(__N(__s));
1330 _M_erase_at_end(iterator __pos)
1331 { this->_M_impl._M_finish = __pos; }
1334 _M_erase(iterator __pos);
1337 _M_erase(iterator __first, iterator __last);