696 class vector<bool, _Alloc> :
protected _Bvector_base<_Alloc>
698 typedef _Bvector_base<_Alloc> _Base;
699 typedef typename _Base::_Bit_pointer _Bit_pointer;
700 typedef typename _Base::_Bit_alloc_traits _Bit_alloc_traits;
702#if __cplusplus >= 201103L
707 typedef bool value_type;
708 typedef size_t size_type;
709 typedef ptrdiff_t difference_type;
710 typedef _Bit_reference reference;
711 typedef bool const_reference;
712 typedef _Bit_reference* pointer;
713 typedef const bool* const_pointer;
714 typedef _Bit_iterator iterator;
715 typedef _Bit_const_iterator const_iterator;
718 typedef _Alloc allocator_type;
723 {
return _Base::get_allocator(); }
726 using _Base::_M_allocate;
727 using _Base::_M_deallocate;
728 using _Base::_S_nword;
729 using _Base::_M_get_Bit_allocator;
732#if __cplusplus >= 201103L
740 vector(
const allocator_type& __a)
743#if __cplusplus >= 201103L
746 vector(size_type __n,
const allocator_type& __a = allocator_type())
751 vector(size_type __n,
const bool& __value,
752 const allocator_type& __a = allocator_type())
755 vector(size_type __n,
const bool& __value =
bool(),
756 const allocator_type& __a = allocator_type())
760 _M_check_and_initialize(__n);
761 _M_initialize_value(__value);
766 : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator()))
768 _M_initialize(__x.
size());
769 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
772#if __cplusplus >= 201103L
773 vector(vector&&) =
default;
789 _M_initialize(__x.
size());
790 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
797 vector(vector&& __x,
const __type_identity_t<allocator_type>& __a)
798 noexcept(_Bit_alloc_traits::_S_always_equal())
804 vector(
const vector& __x,
const __type_identity_t<allocator_type>& __a)
807 _M_initialize(__x.
size());
808 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
813 const allocator_type& __a = allocator_type())
816 _M_initialize_range(__l.begin(), __l.end(),
821#if __cplusplus >= 201103L
822 template<
typename _InputIterator,
823 typename = std::_RequireInputIter<_InputIterator>>
825 vector(_InputIterator __first, _InputIterator __last,
826 const allocator_type& __a = allocator_type())
829 _M_initialize_range(__first, __last,
833 template<
typename _InputIterator>
834 vector(_InputIterator __first, _InputIterator __last,
835 const allocator_type& __a = allocator_type())
839 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
840 _M_initialize_dispatch(__first, __last, _Integral());
845 ~vector() _GLIBCXX_NOEXCEPT { }
853#if __cplusplus >= 201103L
854 if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
856 if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
858 this->_M_deallocate();
859 std::__alloc_on_copy(_M_get_Bit_allocator(),
860 __x._M_get_Bit_allocator());
861 _M_initialize(__x.
size());
864 std::__alloc_on_copy(_M_get_Bit_allocator(),
865 __x._M_get_Bit_allocator());
868 if (__x.
size() > capacity())
870 this->_M_deallocate();
871 _M_initialize(__x.
size());
873 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
878#if __cplusplus >= 201103L
881 operator=(vector&& __x)
noexcept(_Bit_alloc_traits::_S_nothrow_move())
883 if (_Bit_alloc_traits::_S_propagate_on_move_assign()
884 || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
886 this->_M_deallocate();
888 std::__alloc_on_move(_M_get_Bit_allocator(),
889 __x._M_get_Bit_allocator());
893 if (__x.
size() > capacity())
895 this->_M_deallocate();
896 _M_initialize(__x.
size());
898 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
909 this->
assign(__l.begin(), __l.end());
920 assign(size_type __n,
const bool& __x)
921 { _M_fill_assign(__n, __x); }
923#if __cplusplus >= 201103L
924 template<
typename _InputIterator,
925 typename = std::_RequireInputIter<_InputIterator>>
928 assign(_InputIterator __first, _InputIterator __last)
931 template<
typename _InputIterator>
933 assign(_InputIterator __first, _InputIterator __last)
936 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
937 _M_assign_dispatch(__first, __last, _Integral());
941#if __cplusplus >= 201103L
948 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
950 begin() _GLIBCXX_NOEXCEPT
951 {
return iterator(this->_M_impl._M_start._M_p, 0); }
953 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
955 begin()
const _GLIBCXX_NOEXCEPT
956 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
958 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
960 end() _GLIBCXX_NOEXCEPT
961 {
return this->_M_impl._M_finish; }
963 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
965 end()
const _GLIBCXX_NOEXCEPT
966 {
return this->_M_impl._M_finish; }
968 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
970 rbegin() _GLIBCXX_NOEXCEPT
971 {
return reverse_iterator(
end()); }
973 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
974 const_reverse_iterator
975 rbegin()
const _GLIBCXX_NOEXCEPT
976 {
return const_reverse_iterator(
end()); }
978 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
980 rend() _GLIBCXX_NOEXCEPT
981 {
return reverse_iterator(
begin()); }
983 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
984 const_reverse_iterator
985 rend()
const _GLIBCXX_NOEXCEPT
986 {
return const_reverse_iterator(
begin()); }
988#if __cplusplus >= 201103L
989 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
992 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
994 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
996 cend()
const noexcept
997 {
return this->_M_impl._M_finish; }
999 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1000 const_reverse_iterator
1002 {
return const_reverse_iterator(
end()); }
1004 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1005 const_reverse_iterator
1006 crend()
const noexcept
1007 {
return const_reverse_iterator(
begin()); }
1010 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1012 size()
const _GLIBCXX_NOEXCEPT
1013 {
return size_type(
end() -
begin()); }
1015 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1019 const size_type __isize =
1020 __gnu_cxx::__numeric_traits<difference_type>::__max
1021 - int(_S_word_bit) + 1;
1022 const size_type __asize
1024 return (__asize <= __isize /
int(_S_word_bit)
1025 ? __asize *
int(_S_word_bit) : __isize);
1028 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1031 {
return size_type(const_iterator(this->_M_impl._M_end_addr(), 0)
1034 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1036 empty()
const _GLIBCXX_NOEXCEPT
1039 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1042 {
return begin()[__n]; }
1044 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1047 {
return begin()[__n]; }
1050 _GLIBCXX20_CONSTEXPR
1054 if (__n >= this->
size())
1055 __throw_out_of_range_fmt(__N(
"vector<bool>::_M_range_check: __n "
1056 "(which is %zu) >= this->size() "
1062 _GLIBCXX20_CONSTEXPR
1067 return (*
this)[__n];
1070 _GLIBCXX20_CONSTEXPR
1072 at(size_type __n)
const
1075 return (*
this)[__n];
1078 _GLIBCXX20_CONSTEXPR
1083 __throw_length_error(__N(
"vector::reserve"));
1088 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1091 {
return *
begin(); }
1093 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1096 {
return *
begin(); }
1098 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1101 {
return *(
end() - 1); }
1103 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1106 {
return *(
end() - 1); }
1108 _GLIBCXX20_CONSTEXPR
1112 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1113 *this->_M_impl._M_finish++ = __x;
1115 _M_insert_aux(
end(), __x);
1118 _GLIBCXX20_CONSTEXPR
1120 swap(vector& __x) _GLIBCXX_NOEXCEPT
1122#if __cplusplus >= 201103L
1123 __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value
1124 || _M_get_Bit_allocator() == __x._M_get_Bit_allocator());
1126 this->_M_impl._M_swap_data(__x._M_impl);
1127 _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(),
1128 __x._M_get_Bit_allocator());
1132 _GLIBCXX20_CONSTEXPR
1134 swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT
1141 _GLIBCXX20_CONSTEXPR
1143#if __cplusplus >= 201103L
1144 insert(const_iterator __position,
const bool& __x)
1146 insert(iterator __position,
const bool& __x)
1149 const difference_type __n = __position -
begin();
1150 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()
1151 && __position == end())
1152 *this->_M_impl._M_finish++ = __x;
1154 _M_insert_aux(__position._M_const_cast(), __x);
1155 return begin() + __n;
1158#if _GLIBCXX_USE_DEPRECATED
1159 _GLIBCXX_DEPRECATED_SUGGEST(
"insert(position, false)")
1161 insert(const_iterator __position)
1162 {
return this->
insert(__position._M_const_cast(),
false); }
1165#if __cplusplus >= 201103L
1166 template<
typename _InputIterator,
1167 typename = std::_RequireInputIter<_InputIterator>>
1168 _GLIBCXX20_CONSTEXPR
1170 insert(const_iterator __position,
1171 _InputIterator __first, _InputIterator __last)
1173 difference_type __offset = __position -
cbegin();
1174 _M_insert_range(__position._M_const_cast(),
1177 return begin() + __offset;
1180 template<
typename _InputIterator>
1182 insert(iterator __position,
1183 _InputIterator __first, _InputIterator __last)
1186 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1187 _M_insert_dispatch(__position, __first, __last, _Integral());
1191#if __cplusplus >= 201103L
1192 _GLIBCXX20_CONSTEXPR
1194 insert(const_iterator __position, size_type __n,
const bool& __x)
1196 difference_type __offset = __position -
cbegin();
1197 _M_fill_insert(__position._M_const_cast(), __n, __x);
1198 return begin() + __offset;
1202 insert(iterator __position, size_type __n,
const bool& __x)
1203 { _M_fill_insert(__position, __n, __x); }
1206#if __cplusplus >= 201103L
1207 _GLIBCXX20_CONSTEXPR
1210 {
return this->
insert(__p, __l.begin(), __l.end()); }
1213 _GLIBCXX20_CONSTEXPR
1216 { --this->_M_impl._M_finish; }
1218 _GLIBCXX20_CONSTEXPR
1220#if __cplusplus >= 201103L
1221 erase(const_iterator __position)
1223 erase(iterator __position)
1225 {
return _M_erase(__position._M_const_cast()); }
1227 _GLIBCXX20_CONSTEXPR
1229#if __cplusplus >= 201103L
1230 erase(const_iterator __first, const_iterator __last)
1232 erase(iterator __first, iterator __last)
1234 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1236 _GLIBCXX20_CONSTEXPR
1238 resize(size_type __new_size,
bool __x =
bool())
1240 if (__new_size <
size())
1241 _M_erase_at_end(
begin() + difference_type(__new_size));
1246#if __cplusplus >= 201103L
1247 _GLIBCXX20_CONSTEXPR
1250 { _M_shrink_to_fit(); }
1253 _GLIBCXX20_CONSTEXPR
1255 flip() _GLIBCXX_NOEXCEPT
1257 _Bit_type *
const __end = this->_M_impl._M_end_addr();
1258 for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p)
1262 _GLIBCXX20_CONSTEXPR
1264 clear() _GLIBCXX_NOEXCEPT
1265 { _M_erase_at_end(
begin()); }
1267#if __cplusplus >= 201103L
1268 template<
typename... _Args>
1269#if __cplusplus > 201402L
1270 _GLIBCXX20_CONSTEXPR
1275 emplace_back(_Args&&... __args)
1278#if __cplusplus > 201402L
1283 template<
typename... _Args>
1284 _GLIBCXX20_CONSTEXPR
1286 emplace(const_iterator __pos, _Args&&... __args)
1287 {
return insert(__pos,
bool(__args...)); }
1292 _GLIBCXX20_CONSTEXPR
1294 _M_copy_aligned(const_iterator __first, const_iterator __last,
1297 _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
1298 return std::copy(const_iterator(__last._M_p, 0), __last,
1302 _GLIBCXX20_CONSTEXPR
1304 _M_initialize(size_type __n)
1307 _GLIBCXX_DEBUG_ASSERT(__n <= (
size_t)-_S_word_bit);
1311 _Bit_pointer __q = this->_M_allocate(__n);
1312 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1314 this->_M_impl._M_start = __start;
1315 this->_M_impl._M_finish = __start + difference_type(__n);
1319 template<
typename _SizeT>
1320 _GLIBCXX20_CONSTEXPR
1322 _M_check_and_initialize(_SizeT __n)
1325 __throw_length_error(
1326 __N(
"Cannot create std::vector<bool> larger than max_size()"));
1327 _M_initialize(
static_cast<size_type
>(__n));
1330 _GLIBCXX20_CONSTEXPR
1332 _M_initialize_value(
bool __x) _GLIBCXX_NOEXCEPT
1334 if (_Bit_type* __p = this->_M_impl._M_start._M_p)
1335 __fill_bvector_n(__p, this->_M_impl._M_end_addr() - __p, __x);
1338 _GLIBCXX20_CONSTEXPR
1340 _M_reallocate(size_type __n);
1342#if __cplusplus >= 201103L
1343 _GLIBCXX20_CONSTEXPR
1348#if __cplusplus < 201103L
1351 template<
typename _Integer>
1353 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1355 _M_check_and_initialize(
static_cast<size_type
>(__n));
1356 _M_initialize_value(__x);
1359 template<
typename _InputIterator>
1361 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1363 { _M_initialize_range(__first, __last,
1367 template<
typename _InputIterator>
1368 _GLIBCXX20_CONSTEXPR
1370 _M_initialize_range(_InputIterator __first, _InputIterator __last,
1373 for (; __first != __last; ++__first)
1377 template<
typename _ForwardIterator>
1378 _GLIBCXX20_CONSTEXPR
1380 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
1384 std::copy(__first, __last,
begin());
1387#if __cplusplus < 201103L
1390 template<
typename _Integer>
1392 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1393 { _M_fill_assign(__n, __val); }
1395 template<
class _InputIterator>
1397 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1402 _GLIBCXX20_CONSTEXPR
1404 _M_fill_assign(
size_t __n,
bool __x)
1408 _M_initialize_value(__x);
1413 _M_erase_at_end(
begin() + __n);
1414 _M_initialize_value(__x);
1418 template<
typename _InputIterator>
1419 _GLIBCXX20_CONSTEXPR
1421 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1424 iterator __cur =
begin();
1425 for (; __first != __last && __cur !=
end(); ++__cur, (void)++__first)
1427 if (__first == __last)
1428 _M_erase_at_end(__cur);
1433 template<
typename _ForwardIterator>
1434 _GLIBCXX20_CONSTEXPR
1436 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1441 _M_erase_at_end(std::copy(__first, __last,
begin()));
1444 _ForwardIterator __mid = __first;
1446 std::copy(__first, __mid,
begin());
1451#if __cplusplus < 201103L
1454 template<
typename _Integer>
1456 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
1458 { _M_fill_insert(__pos, __n, __x); }
1460 template<
typename _InputIterator>
1462 _M_insert_dispatch(iterator __pos,
1463 _InputIterator __first, _InputIterator __last,
1465 { _M_insert_range(__pos, __first, __last,
1469 _GLIBCXX20_CONSTEXPR
1471 _M_fill_insert(iterator __position, size_type __n,
bool __x);
1473 template<
typename _InputIterator>
1474 _GLIBCXX20_CONSTEXPR
1476 _M_insert_range(iterator __pos, _InputIterator __first,
1479 for (; __first != __last; ++__first)
1481 __pos =
insert(__pos, *__first);
1486 template<
typename _ForwardIterator>
1487 _GLIBCXX20_CONSTEXPR
1489 _M_insert_range(iterator __position, _ForwardIterator __first,
1492 _GLIBCXX20_CONSTEXPR
1494 _M_insert_aux(iterator __position,
bool __x);
1496 _GLIBCXX20_CONSTEXPR
1498 _M_check_len(size_type __n,
const char* __s)
const
1501 __throw_length_error(__N(__s));
1507 _GLIBCXX20_CONSTEXPR
1509 _M_erase_at_end(iterator __pos)
1510 { this->_M_impl._M_finish = __pos; }
1512 _GLIBCXX20_CONSTEXPR
1514 _M_erase(iterator __pos);
1516 _GLIBCXX20_CONSTEXPR
1518 _M_erase(iterator __first, iterator __last);
1526#if __cplusplus >= 201103L
1527 void data() =
delete;