749 class vector<bool, _Alloc> :
protected _Bvector_base<_Alloc>
751 typedef _Bvector_base<_Alloc> _Base;
752 typedef typename _Base::_Bit_pointer _Bit_pointer;
753 typedef typename _Base::_Bit_alloc_traits _Bit_alloc_traits;
755#if __cplusplus >= 201103L
757# if __cplusplus > 201703L
759 "std::vector must have the same value_type as its allocator");
764 typedef bool value_type;
765 typedef size_t size_type;
766 typedef ptrdiff_t difference_type;
767 typedef _Bit_reference reference;
768 typedef bool const_reference;
769 typedef _Bit_reference* pointer;
770 typedef const bool* const_pointer;
771 typedef _Bit_iterator iterator;
772 typedef _Bit_const_iterator const_iterator;
775 typedef _Alloc allocator_type;
780 {
return _Base::get_allocator(); }
783 using _Base::_M_allocate;
784 using _Base::_M_deallocate;
785 using _Base::_S_nword;
786 using _Base::_M_get_Bit_allocator;
789#if __cplusplus >= 201103L
797 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
800#if __cplusplus >= 201103L
803 vector(size_type __n,
const allocator_type& __a = allocator_type())
808 vector(size_type __n,
const bool& __value,
809 const allocator_type& __a = allocator_type())
812 vector(size_type __n,
const bool& __value =
bool(),
813 const allocator_type& __a = allocator_type())
818 _M_initialize_value(__value);
823 : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator()))
825 const_iterator __xbegin = __x.
begin(), __xend = __x.
end();
826 _M_initialize(__x.
size());
827 _M_copy_aligned(__xbegin, __xend,
begin());
830#if __cplusplus >= 201103L
831 vector(vector&&) =
default;
847 _M_initialize(__x.
size());
848 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
855 vector(vector&& __x,
const __type_identity_t<allocator_type>& __a)
856 noexcept(_Bit_alloc_traits::_S_always_equal())
862 vector(
const vector& __x,
const __type_identity_t<allocator_type>& __a)
865 _M_initialize(__x.
size());
866 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
871 const allocator_type& __a = allocator_type())
874 _M_initialize_range(__l.begin(), __l.end(),
879#if __cplusplus >= 201103L
880 template<
typename _InputIterator,
881 typename = std::_RequireInputIter<_InputIterator>>
883 vector(_InputIterator __first, _InputIterator __last,
884 const allocator_type& __a = allocator_type())
887 _M_initialize_range(__first, __last,
888 std::__iterator_category(__first));
891 template<
typename _InputIterator>
892 vector(_InputIterator __first, _InputIterator __last,
893 const allocator_type& __a = allocator_type())
897 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
898 _M_initialize_dispatch(__first, __last, _Integral());
902#if __glibcxx_containers_ranges
908 template<__detail::__container_compatible_range<
bool> _Rg>
910 vector(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
915 _M_initialize(size_type(ranges::distance(__rg)));
916 ranges::copy(__rg,
begin());
920 auto __first = ranges::begin(__rg);
921 const auto __last = ranges::end(__rg);
922 for (; __first != __last; ++__first)
923 emplace_back(*__first);
929 ~vector() _GLIBCXX_NOEXCEPT { }
937#if __cplusplus >= 201103L
938 if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
940 if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
942 this->_M_deallocate();
943 std::__alloc_on_copy(_M_get_Bit_allocator(),
944 __x._M_get_Bit_allocator());
945 _M_initialize(__x.
size());
948 std::__alloc_on_copy(_M_get_Bit_allocator(),
949 __x._M_get_Bit_allocator());
952 if (__x.
size() > capacity())
954 this->_M_deallocate();
955 _M_initialize(__x.
size());
957 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
962#if __cplusplus >= 201103L
965 operator=(vector&& __x)
noexcept(_Bit_alloc_traits::_S_nothrow_move())
967 if (_Bit_alloc_traits::_S_propagate_on_move_assign()
968 || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
970 this->_M_deallocate();
972 std::__alloc_on_move(_M_get_Bit_allocator(),
973 __x._M_get_Bit_allocator());
977 if (__x.
size() > capacity())
979 this->_M_deallocate();
980 _M_initialize(__x.
size());
982 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
993 this->
assign(__l.begin(), __l.end());
1002 _GLIBCXX20_CONSTEXPR
1004 assign(size_type __n,
const bool& __x)
1005 { _M_fill_assign(__n, __x); }
1007#if __cplusplus >= 201103L
1008 template<
typename _InputIterator,
1009 typename = std::_RequireInputIter<_InputIterator>>
1010 _GLIBCXX20_CONSTEXPR
1012 assign(_InputIterator __first, _InputIterator __last)
1013 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
1015 template<
typename _InputIterator>
1017 assign(_InputIterator __first, _InputIterator __last)
1020 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1021 _M_assign_dispatch(__first, __last, _Integral());
1025#if __cplusplus >= 201103L
1026 _GLIBCXX20_CONSTEXPR
1032#if __glibcxx_containers_ranges
1039 template<__detail::__container_compatible_range<
bool> _Rg>
1041 assign_range(_Rg&& __rg)
1046 if (
auto __n = size_type(ranges::distance(__rg)))
1049 this->_M_impl._M_finish
1058 auto __first = ranges::begin(__rg);
1059 const auto __last = ranges::end(__rg);
1060 for (; __first != __last; ++__first)
1061 emplace_back(*__first);
1066 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1068 begin() _GLIBCXX_NOEXCEPT
1069 {
return iterator(this->_M_impl._M_start._M_p, 0); }
1071 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1073 begin()
const _GLIBCXX_NOEXCEPT
1074 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
1076 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1078 end() _GLIBCXX_NOEXCEPT
1079 {
return this->_M_impl._M_finish; }
1081 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1083 end()
const _GLIBCXX_NOEXCEPT
1084 {
return this->_M_impl._M_finish; }
1086 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1088 rbegin() _GLIBCXX_NOEXCEPT
1089 {
return reverse_iterator(
end()); }
1091 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1092 const_reverse_iterator
1093 rbegin()
const _GLIBCXX_NOEXCEPT
1094 {
return const_reverse_iterator(
end()); }
1096 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1098 rend() _GLIBCXX_NOEXCEPT
1099 {
return reverse_iterator(
begin()); }
1101 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1102 const_reverse_iterator
1103 rend()
const _GLIBCXX_NOEXCEPT
1104 {
return const_reverse_iterator(
begin()); }
1106#if __cplusplus >= 201103L
1107 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1110 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
1112 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1114 cend()
const noexcept
1115 {
return this->_M_impl._M_finish; }
1117 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1118 const_reverse_iterator
1120 {
return const_reverse_iterator(
end()); }
1122 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1123 const_reverse_iterator
1124 crend()
const noexcept
1125 {
return const_reverse_iterator(
begin()); }
1128 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1130 size()
const _GLIBCXX_NOEXCEPT
1131 {
return size_type(
end() -
begin()); }
1133 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1137 const size_type __isize =
1138 __gnu_cxx::__numeric_traits<difference_type>::__max
1139 - int(_S_word_bit) + 1;
1140 const size_type __asize
1142 return (__asize <= __isize /
int(_S_word_bit)
1143 ? __asize *
int(_S_word_bit) : __isize);
1146 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1149 {
return size_type(const_iterator(this->_M_impl._M_end_addr(), 0)
1152 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1154 empty()
const _GLIBCXX_NOEXCEPT
1157 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1161 __glibcxx_requires_subscript(__n);
1162 return _Bit_reference (this->_M_impl._M_start._M_p
1163 + __n /
int(_S_word_bit),
1164 1UL << __n %
int(_S_word_bit));
1167 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1171 __glibcxx_requires_subscript(__n);
1172 return _Bit_reference (this->_M_impl._M_start._M_p
1173 + __n /
int(_S_word_bit),
1174 1UL << __n %
int(_S_word_bit));
1178 _GLIBCXX20_CONSTEXPR
1182 if (__n >= this->
size())
1183 __throw_out_of_range_fmt(__N(
"vector<bool>::_M_range_check: __n "
1184 "(which is %zu) >= this->size() "
1190 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1195 return (*
this)[__n];
1198 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1200 at(size_type __n)
const
1203 return (*
this)[__n];
1206 _GLIBCXX20_CONSTEXPR
1211 __throw_length_error(__N(
"vector::reserve"));
1216 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1220 __glibcxx_requires_nonempty();
1224 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1228 __glibcxx_requires_nonempty();
1232 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1236 __glibcxx_requires_nonempty();
1237 return *(
end() - 1);
1240 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1244 __glibcxx_requires_nonempty();
1245 return *(
end() - 1);
1248 _GLIBCXX20_CONSTEXPR
1252 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1253 *this->_M_impl._M_finish++ = __x;
1255 _M_insert_aux(
end(), __x);
1258 _GLIBCXX20_CONSTEXPR
1260 swap(vector& __x) _GLIBCXX_NOEXCEPT
1262#if __cplusplus >= 201103L
1263 __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value
1264 || _M_get_Bit_allocator() == __x._M_get_Bit_allocator());
1266 this->_M_impl._M_swap_data(__x._M_impl);
1267 _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(),
1268 __x._M_get_Bit_allocator());
1272 _GLIBCXX26_DEPRECATED_SUGGEST(
"swap' invoked via ADL or 'std::ranges::swap")
1273 _GLIBCXX20_CONSTEXPR
1275 swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT
1282 _GLIBCXX20_CONSTEXPR
1284#if __cplusplus >= 201103L
1285 insert(const_iterator __position,
const bool& __x)
1287 insert(iterator __position,
const bool& __x)
1290 const difference_type __n = __position -
begin();
1291 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()
1292 && __position == end())
1293 *this->_M_impl._M_finish++ = __x;
1295 _M_insert_aux(__position._M_const_cast(), __x);
1296 return begin() + __n;
1299#if _GLIBCXX_USE_DEPRECATED
1300 _GLIBCXX_DEPRECATED_SUGGEST(
"insert(position, false)")
1302 insert(const_iterator __position)
1303 {
return this->
insert(__position._M_const_cast(),
false); }
1306#if __cplusplus >= 201103L
1307 template<
typename _InputIterator,
1308 typename = std::_RequireInputIter<_InputIterator>>
1309 _GLIBCXX20_CONSTEXPR
1311 insert(const_iterator __position,
1312 _InputIterator __first, _InputIterator __last)
1314 difference_type __offset = __position -
cbegin();
1315 _M_insert_range(__position._M_const_cast(),
1317 std::__iterator_category(__first));
1318 return begin() + __offset;
1321 template<
typename _InputIterator>
1323 insert(iterator __position,
1324 _InputIterator __first, _InputIterator __last)
1327 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1328 _M_insert_dispatch(__position, __first, __last, _Integral());
1332#if __cplusplus >= 201103L
1333 _GLIBCXX20_CONSTEXPR
1335 insert(const_iterator __position, size_type __n,
const bool& __x)
1337 difference_type __offset = __position -
cbegin();
1338 _M_fill_insert(__position._M_const_cast(), __n, __x);
1339 return begin() + __offset;
1343 insert(iterator __position, size_type __n,
const bool& __x)
1344 { _M_fill_insert(__position, __n, __x); }
1347#if __cplusplus >= 201103L
1348 _GLIBCXX20_CONSTEXPR
1351 {
return this->
insert(__p, __l.begin(), __l.end()); }
1354#if __glibcxx_containers_ranges
1363 template<__detail::__container_compatible_range<
bool> _Rg>
1365 insert_range(const_iterator __pos, _Rg&& __rg)
1369 if (
auto __n = size_type(ranges::distance(__rg)))
1373 std::copy_backward(__pos._M_const_cast(), end(),
1374 this->_M_impl._M_finish
1375 + difference_type(__n));
1376 ranges::copy(__rg, __pos._M_const_cast());
1377 this->_M_impl._M_finish += difference_type(__n);
1378 return __pos._M_const_cast();
1382 const size_type __len =
1383 _M_check_len(__n,
"vector<bool>::insert_range");
1384 const iterator __begin =
begin(), __end =
end();
1385 _Bit_pointer __q = this->_M_allocate(__len);
1387 iterator __i = _M_copy_aligned(__begin,
1388 __pos._M_const_cast(),
1390 iterator __j = ranges::copy(__rg, __i).out;
1391 iterator __finish = std::copy(__pos._M_const_cast(),
1393 this->_M_deallocate();
1394 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
1395 this->_M_impl._M_start = __start;
1396 this->_M_impl._M_finish = __finish;
1401 return __pos._M_const_cast();
1404 return insert_range(__pos,
1412 template<__detail::__container_compatible_range<
bool> _Rg>
1414 append_range(_Rg&& __rg)
1421 const auto __n = size_type(ranges::distance(__rg));
1428 const auto __sz =
size();
1429 const auto __capacity =
capacity();
1430 if ((__capacity - __sz) >= __n)
1432 this->_M_impl._M_finish
1438 __tmp.
reserve(_M_check_len(__n,
"vector::append_range"));
1439 __tmp._M_impl._M_finish
1441 __tmp._M_impl._M_finish
1447 auto __first = ranges::begin(__rg);
1448 const auto __last = ranges::end(__rg);
1452 __first != __last && __free > 0;
1453 ++__first, (void) --__free)
1454 emplace_back(*__first);
1456 if (__first == __last)
1467 _GLIBCXX20_CONSTEXPR
1470 { --this->_M_impl._M_finish; }
1472 _GLIBCXX20_CONSTEXPR
1474#if __cplusplus >= 201103L
1475 erase(const_iterator __position)
1477 erase(iterator __position)
1479 {
return _M_erase(__position._M_const_cast()); }
1481 _GLIBCXX20_CONSTEXPR
1483#if __cplusplus >= 201103L
1484 erase(const_iterator __first, const_iterator __last)
1486 erase(iterator __first, iterator __last)
1488 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1490 _GLIBCXX20_CONSTEXPR
1492 resize(size_type __new_size,
bool __x =
bool())
1494 if (__new_size <
size())
1495 _M_erase_at_end(
begin() + difference_type(__new_size));
1500#if __cplusplus >= 201103L
1501 _GLIBCXX20_CONSTEXPR
1504 { _M_shrink_to_fit(); }
1507 _GLIBCXX20_CONSTEXPR
1509 flip() _GLIBCXX_NOEXCEPT
1511 _Bit_type *
const __end = this->_M_impl._M_end_addr();
1512 for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p)
1516 _GLIBCXX20_CONSTEXPR
1518 clear() _GLIBCXX_NOEXCEPT
1519 { _M_erase_at_end(
begin()); }
1521#if __cplusplus >= 201103L
1522 template<
typename... _Args>
1523#if __cplusplus > 201402L
1524 _GLIBCXX20_CONSTEXPR
1529 emplace_back(_Args&&... __args)
1532#if __cplusplus > 201402L
1537 template<
typename... _Args>
1538 _GLIBCXX20_CONSTEXPR
1540 emplace(const_iterator __pos, _Args&&... __args)
1546 _GLIBCXX20_CONSTEXPR
1548 _M_copy_aligned(const_iterator __first, const_iterator __last,
1551 _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
1552 return std::copy(const_iterator(__last._M_p, 0), __last,
1556 _GLIBCXX20_CONSTEXPR
1558 _M_initialize(size_type __n)
1562 _Bit_pointer __q = this->_M_allocate(__n);
1563 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1565 this->_M_impl._M_start = __start;
1566 this->_M_impl._M_finish = __start + difference_type(__n);
1570 _GLIBCXX20_CONSTEXPR
1572 _M_initialize_value(
bool __x) _GLIBCXX_NOEXCEPT
1574 if (_Bit_type* __p = this->_M_impl._M_start._M_p)
1575 __fill_bvector_n(__p, this->_M_impl._M_end_addr() - __p, __x);
1578 _GLIBCXX20_CONSTEXPR
1580 _M_reallocate(size_type __n);
1582#if __cplusplus >= 201103L
1583 _GLIBCXX20_CONSTEXPR
1588#if __cplusplus < 201103L
1591 template<
typename _Integer>
1593 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1595 _M_initialize(
static_cast<size_type
>(__n));
1596 _M_initialize_value(__x);
1599 template<
typename _InputIterator>
1601 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1603 { _M_initialize_range(__first, __last,
1604 std::__iterator_category(__first)); }
1607 template<
typename _InputIterator>
1608 _GLIBCXX20_CONSTEXPR
1610 _M_initialize_range(_InputIterator __first, _InputIterator __last,
1613 for (; __first != __last; ++__first)
1617 template<
typename _ForwardIterator>
1618 _GLIBCXX20_CONSTEXPR
1620 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
1625 std::copy(__first, __last,
begin());
1628#if __cplusplus < 201103L
1631 template<
typename _Integer>
1633 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1634 { _M_fill_assign(__n, __val); }
1636 template<
class _InputIterator>
1638 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1640 { _M_assign_aux(__first, __last, std::__iterator_category(__first)); }
1643 _GLIBCXX20_CONSTEXPR
1645 _M_fill_assign(
size_t __n,
bool __x)
1649 _M_initialize_value(__x);
1654 _M_erase_at_end(
begin() + __n);
1655 _M_initialize_value(__x);
1659 template<
typename _InputIterator>
1660 _GLIBCXX20_CONSTEXPR
1662 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1665 iterator __cur =
begin();
1666 for (; __first != __last && __cur !=
end(); ++__cur, (void)++__first)
1668 if (__first == __last)
1669 _M_erase_at_end(__cur);
1674 template<
typename _ForwardIterator>
1675 _GLIBCXX20_CONSTEXPR
1677 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1682 _M_erase_at_end(std::copy(__first, __last,
begin()));
1685 _ForwardIterator __mid = __first;
1687 std::copy(__first, __mid,
begin());
1692#if __cplusplus < 201103L
1695 template<
typename _Integer>
1697 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
1699 { _M_fill_insert(__pos, __n, __x); }
1701 template<
typename _InputIterator>
1703 _M_insert_dispatch(iterator __pos,
1704 _InputIterator __first, _InputIterator __last,
1706 { _M_insert_range(__pos, __first, __last,
1707 std::__iterator_category(__first)); }
1710 _GLIBCXX20_CONSTEXPR
1712 _M_fill_insert(iterator __position, size_type __n,
bool __x);
1714 template<
typename _InputIterator>
1715 _GLIBCXX20_CONSTEXPR
1717 _M_insert_range(iterator __pos, _InputIterator __first,
1720 for (; __first != __last; ++__first)
1722 __pos =
insert(__pos, *__first);
1727 template<
typename _ForwardIterator>
1728 _GLIBCXX20_CONSTEXPR
1730 _M_insert_range(iterator __position, _ForwardIterator __first,
1733 _GLIBCXX20_CONSTEXPR
1735 _M_insert_aux(iterator __position,
bool __x);
1737 _GLIBCXX20_CONSTEXPR
1739 _M_check_len(size_type __n,
const char* __s)
const
1742 __throw_length_error(__N(__s));
1748 _GLIBCXX20_CONSTEXPR
1750 _M_erase_at_end(iterator __pos)
1751 { this->_M_impl._M_finish = __pos; }
1753 _GLIBCXX20_CONSTEXPR
1755 _M_erase(iterator __pos);
1757 _GLIBCXX20_CONSTEXPR
1759 _M_erase(iterator __first, iterator __last);
1767#if __cplusplus >= 201103L
1768 void data() =
delete;