746 class vector<bool, _Alloc> :
protected _Bvector_base<_Alloc>
748 typedef _Bvector_base<_Alloc> _Base;
749 typedef typename _Base::_Bit_pointer _Bit_pointer;
752#if __cplusplus >= 201103L
757 typedef bool value_type;
758 typedef size_t size_type;
759 typedef ptrdiff_t difference_type;
760 typedef _Bit_reference reference;
761 typedef bool const_reference;
762 typedef _Bit_reference* pointer;
763 typedef const bool* const_pointer;
764 typedef _Bit_iterator iterator;
765 typedef _Bit_const_iterator const_iterator;
768 typedef _Alloc allocator_type;
773 {
return _Base::get_allocator(); }
776 using _Base::_M_allocate;
777 using _Base::_M_deallocate;
778 using _Base::_S_nword;
779 using _Base::_M_get_Bit_allocator;
782#if __cplusplus >= 201103L
790 vector(
const allocator_type& __a) _GLIBCXX_NOEXCEPT
793#if __cplusplus >= 201103L
796 vector(size_type __n,
const allocator_type& __a = allocator_type())
801 vector(size_type __n,
const bool& __value,
802 const allocator_type& __a = allocator_type())
805 vector(size_type __n,
const bool& __value =
bool(),
806 const allocator_type& __a = allocator_type())
811 _M_initialize_value(__value);
816 : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator()))
818 const_iterator __xbegin = __x.
begin(), __xend = __x.
end();
819 _M_initialize(__x.
size());
820 _M_copy_aligned(__xbegin, __xend,
begin());
823#if __cplusplus >= 201103L
840 _M_initialize(__x.
size());
848 vector(
vector&& __x,
const __type_identity_t<allocator_type>& __a)
849 noexcept(_Bit_alloc_traits::_S_always_equal())
855 vector(
const vector& __x,
const __type_identity_t<allocator_type>& __a)
858 _M_initialize(__x.
size());
864 const allocator_type& __a = allocator_type())
867 _M_initialize_range(__l.begin(), __l.end(),
872#if __cplusplus >= 201103L
873 template<
typename _InputIterator,
874 typename = std::_RequireInputIter<_InputIterator>>
876 vector(_InputIterator __first, _InputIterator __last,
877 const allocator_type& __a = allocator_type())
880 _M_initialize_range(__first, __last,
884 template<
typename _InputIterator>
885 vector(_InputIterator __first, _InputIterator __last,
886 const allocator_type& __a = allocator_type())
890 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
891 _M_initialize_dispatch(__first, __last, _Integral());
895#if __glibcxx_ranges_to_container
900 template<__detail::__container_compatible_range<
bool> _Rg>
902 vector(from_range_t, _Rg&& __rg,
const _Alloc& __a = _Alloc())
905 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
907 _M_initialize(size_type(ranges::distance(__rg)));
908 ranges::copy(__rg,
begin());
912 auto __first = ranges::begin(__rg);
913 const auto __last = ranges::end(__rg);
914 for (; __first != __last; ++__first)
915 emplace_back(*__first);
921 ~vector() _GLIBCXX_NOEXCEPT { }
929#if __cplusplus >= 201103L
930 if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
932 if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
934 this->_M_deallocate();
935 std::__alloc_on_copy(_M_get_Bit_allocator(),
936 __x._M_get_Bit_allocator());
937 _M_initialize(__x.
size());
940 std::__alloc_on_copy(_M_get_Bit_allocator(),
941 __x._M_get_Bit_allocator());
946 this->_M_deallocate();
947 _M_initialize(__x.
size());
949 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
954#if __cplusplus >= 201103L
959 if (_Bit_alloc_traits::_S_propagate_on_move_assign()
960 || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
962 this->_M_deallocate();
964 std::__alloc_on_move(_M_get_Bit_allocator(),
965 __x._M_get_Bit_allocator());
971 this->_M_deallocate();
972 _M_initialize(__x.
size());
974 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
985 this->
assign(__l.begin(), __l.end());
996 assign(size_type __n,
const bool& __x)
997 { _M_fill_assign(__n, __x); }
999#if __cplusplus >= 201103L
1000 template<
typename _InputIterator,
1001 typename = std::_RequireInputIter<_InputIterator>>
1002 _GLIBCXX20_CONSTEXPR
1004 assign(_InputIterator __first, _InputIterator __last)
1007 template<
typename _InputIterator>
1009 assign(_InputIterator __first, _InputIterator __last)
1012 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1013 _M_assign_dispatch(__first, __last, _Integral());
1017#if __cplusplus >= 201103L
1018 _GLIBCXX20_CONSTEXPR
1024#if __glibcxx_ranges_to_container
1029 template<__detail::__container_compatible_range<
bool> _Rg>
1031 assign_range(_Rg&& __rg)
1033 static_assert(assignable_from<bool&, ranges::range_reference_t<_Rg>>);
1039 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1041 begin() _GLIBCXX_NOEXCEPT
1042 {
return iterator(this->_M_impl._M_start._M_p, 0); }
1044 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1046 begin()
const _GLIBCXX_NOEXCEPT
1047 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
1049 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1051 end() _GLIBCXX_NOEXCEPT
1052 {
return this->_M_impl._M_finish; }
1054 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1056 end()
const _GLIBCXX_NOEXCEPT
1057 {
return this->_M_impl._M_finish; }
1059 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1061 rbegin() _GLIBCXX_NOEXCEPT
1064 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1066 rbegin()
const _GLIBCXX_NOEXCEPT
1069 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1071 rend() _GLIBCXX_NOEXCEPT
1074 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1076 rend()
const _GLIBCXX_NOEXCEPT
1079#if __cplusplus >= 201103L
1080 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1083 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
1085 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1087 cend()
const noexcept
1088 {
return this->_M_impl._M_finish; }
1090 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1095 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1097 crend()
const noexcept
1101 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1103 size()
const _GLIBCXX_NOEXCEPT
1104 {
return size_type(
end() -
begin()); }
1106 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1110 const size_type __isize =
1111 __gnu_cxx::__numeric_traits<difference_type>::__max
1112 - int(_S_word_bit) + 1;
1113 const size_type __asize
1114 = _Bit_alloc_traits::max_size(_M_get_Bit_allocator());
1115 return (__asize <= __isize /
int(_S_word_bit)
1116 ? __asize *
int(_S_word_bit) : __isize);
1119 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1122 {
return size_type(const_iterator(this->_M_impl._M_end_addr(), 0)
1125 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1127 empty()
const _GLIBCXX_NOEXCEPT
1130 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1134 __glibcxx_requires_subscript(__n);
1135 return begin()[__n];
1138 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1142 __glibcxx_requires_subscript(__n);
1143 return begin()[__n];
1147 _GLIBCXX20_CONSTEXPR
1151 if (__n >= this->
size())
1152 __throw_out_of_range_fmt(__N(
"vector<bool>::_M_range_check: __n "
1153 "(which is %zu) >= this->size() "
1159 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1164 return (*
this)[__n];
1167 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1169 at(size_type __n)
const
1172 return (*
this)[__n];
1175 _GLIBCXX20_CONSTEXPR
1180 __throw_length_error(__N(
"vector::reserve"));
1185 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1189 __glibcxx_requires_nonempty();
1193 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1197 __glibcxx_requires_nonempty();
1201 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1205 __glibcxx_requires_nonempty();
1206 return *(
end() - 1);
1209 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1213 __glibcxx_requires_nonempty();
1214 return *(
end() - 1);
1217 _GLIBCXX20_CONSTEXPR
1221 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1222 *this->_M_impl._M_finish++ = __x;
1224 _M_insert_aux(
end(), __x);
1227 _GLIBCXX20_CONSTEXPR
1231#if __cplusplus >= 201103L
1232 __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value
1233 || _M_get_Bit_allocator() == __x._M_get_Bit_allocator());
1235 this->_M_impl._M_swap_data(__x._M_impl);
1236 _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(),
1237 __x._M_get_Bit_allocator());
1241 _GLIBCXX20_CONSTEXPR
1243 swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT
1250 _GLIBCXX20_CONSTEXPR
1252#if __cplusplus >= 201103L
1253 insert(const_iterator __position,
const bool& __x)
1255 insert(iterator __position,
const bool& __x)
1258 const difference_type __n = __position -
begin();
1259 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()
1260 && __position ==
end())
1261 *this->_M_impl._M_finish++ = __x;
1263 _M_insert_aux(__position._M_const_cast(), __x);
1264 return begin() + __n;
1267#if _GLIBCXX_USE_DEPRECATED
1268 _GLIBCXX_DEPRECATED_SUGGEST(
"insert(position, false)")
1270 insert(const_iterator __position)
1271 {
return this->
insert(__position._M_const_cast(),
false); }
1274#if __cplusplus >= 201103L
1275 template<
typename _InputIterator,
1276 typename = std::_RequireInputIter<_InputIterator>>
1277 _GLIBCXX20_CONSTEXPR
1279 insert(const_iterator __position,
1280 _InputIterator __first, _InputIterator __last)
1282 difference_type __offset = __position -
cbegin();
1283 _M_insert_range(__position._M_const_cast(),
1286 return begin() + __offset;
1289 template<
typename _InputIterator>
1291 insert(iterator __position,
1292 _InputIterator __first, _InputIterator __last)
1295 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1296 _M_insert_dispatch(__position, __first, __last, _Integral());
1300#if __cplusplus >= 201103L
1301 _GLIBCXX20_CONSTEXPR
1303 insert(const_iterator __position, size_type __n,
const bool& __x)
1305 difference_type __offset = __position -
cbegin();
1306 _M_fill_insert(__position._M_const_cast(), __n, __x);
1307 return begin() + __offset;
1311 insert(iterator __position, size_type __n,
const bool& __x)
1312 { _M_fill_insert(__position, __n, __x); }
1315#if __cplusplus >= 201103L
1316 _GLIBCXX20_CONSTEXPR
1319 {
return this->
insert(__p, __l.begin(), __l.end()); }
1322#if __glibcxx_ranges_to_container
1327 template<__detail::__container_compatible_range<
bool> _Rg>
1329 insert_range(const_iterator __pos, _Rg&& __rg)
1331 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
1333 if (
auto __n = size_type(ranges::distance(__rg)))
1337 std::copy_backward(__pos._M_const_cast(),
end(),
1338 this->_M_impl._M_finish
1339 + difference_type(__n));
1340 auto __i = ranges::copy(__rg, __pos._M_const_cast()).out;
1341 this->_M_impl._M_finish += difference_type(__n);
1346 const size_type __len =
1347 _M_check_len(__n,
"vector<bool>::insert_range");
1348 const iterator __begin =
begin(), __end =
end();
1349 _Bit_pointer __q = this->_M_allocate(__len);
1351 iterator __i = _M_copy_aligned(__begin,
1352 __pos._M_const_cast(),
1354 __i = ranges::copy(__rg, __i).out;
1355 iterator __finish = std::copy(__pos._M_const_cast(),
1357 this->_M_deallocate();
1358 this->_M_impl._M_end_of_storage = __q + _S_nword(__len);
1359 this->_M_impl._M_start = __start;
1360 this->_M_impl._M_finish = __finish;
1365 return __pos._M_const_cast();
1368 return insert_range(__pos,
1376 template<__detail::__container_compatible_range<
bool> _Rg>
1378 append_range(_Rg&& __rg)
1380 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
1382 reserve(
size() + size_type(ranges::distance(__rg)));
1383 this->_M_impl._M_finish = ranges::copy(__rg,
end()).out;
1387 auto __first = ranges::begin(__rg);
1388 const auto __last = ranges::end(__rg);
1389 size_type __n =
size();
1390 const size_type __cap =
capacity();
1391 for (; __first != __last && __n < __cap; ++__first, (void)++__n)
1392 emplace_back(*__first);
1393 if (__first != __last)
1402 _GLIBCXX20_CONSTEXPR
1405 { --this->_M_impl._M_finish; }
1407 _GLIBCXX20_CONSTEXPR
1409#if __cplusplus >= 201103L
1410 erase(const_iterator __position)
1412 erase(iterator __position)
1414 {
return _M_erase(__position._M_const_cast()); }
1416 _GLIBCXX20_CONSTEXPR
1418#if __cplusplus >= 201103L
1419 erase(const_iterator __first, const_iterator __last)
1421 erase(iterator __first, iterator __last)
1423 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1425 _GLIBCXX20_CONSTEXPR
1427 resize(size_type __new_size,
bool __x =
bool())
1429 if (__new_size <
size())
1430 _M_erase_at_end(
begin() + difference_type(__new_size));
1435#if __cplusplus >= 201103L
1436 _GLIBCXX20_CONSTEXPR
1439 { _M_shrink_to_fit(); }
1442 _GLIBCXX20_CONSTEXPR
1444 flip() _GLIBCXX_NOEXCEPT
1446 _Bit_type *
const __end = this->_M_impl._M_end_addr();
1447 for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p)
1451 _GLIBCXX20_CONSTEXPR
1453 clear() _GLIBCXX_NOEXCEPT
1454 { _M_erase_at_end(
begin()); }
1456#if __cplusplus >= 201103L
1457 template<
typename... _Args>
1458#if __cplusplus > 201402L
1459 _GLIBCXX20_CONSTEXPR
1464 emplace_back(_Args&&... __args)
1467#if __cplusplus > 201402L
1472 template<
typename... _Args>
1473 _GLIBCXX20_CONSTEXPR
1475 emplace(const_iterator __pos, _Args&&... __args)
1481 _GLIBCXX20_CONSTEXPR
1483 _M_copy_aligned(const_iterator __first, const_iterator __last,
1486 _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
1487 return std::copy(const_iterator(__last._M_p, 0), __last,
1491 _GLIBCXX20_CONSTEXPR
1493 _M_initialize(size_type __n)
1497 _Bit_pointer __q = this->_M_allocate(__n);
1498 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1500 this->_M_impl._M_start = __start;
1501 this->_M_impl._M_finish = __start + difference_type(__n);
1505 _GLIBCXX20_CONSTEXPR
1507 _M_initialize_value(
bool __x) _GLIBCXX_NOEXCEPT
1509 if (_Bit_type* __p = this->_M_impl._M_start._M_p)
1510 __fill_bvector_n(__p, this->_M_impl._M_end_addr() - __p, __x);
1513 _GLIBCXX20_CONSTEXPR
1515 _M_reallocate(size_type __n);
1517#if __cplusplus >= 201103L
1518 _GLIBCXX20_CONSTEXPR
1523#if __cplusplus < 201103L
1526 template<
typename _Integer>
1528 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1530 _M_initialize(
static_cast<size_type
>(__n));
1531 _M_initialize_value(__x);
1534 template<
typename _InputIterator>
1536 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1538 { _M_initialize_range(__first, __last,
1542 template<
typename _InputIterator>
1543 _GLIBCXX20_CONSTEXPR
1545 _M_initialize_range(_InputIterator __first, _InputIterator __last,
1548 for (; __first != __last; ++__first)
1552 template<
typename _ForwardIterator>
1553 _GLIBCXX20_CONSTEXPR
1555 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
1560 std::copy(__first, __last,
begin());
1563#if __cplusplus < 201103L
1566 template<
typename _Integer>
1568 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1569 { _M_fill_assign(__n, __val); }
1571 template<
class _InputIterator>
1573 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1578 _GLIBCXX20_CONSTEXPR
1580 _M_fill_assign(
size_t __n,
bool __x)
1584 _M_initialize_value(__x);
1589 _M_erase_at_end(
begin() + __n);
1590 _M_initialize_value(__x);
1594 template<
typename _InputIterator>
1595 _GLIBCXX20_CONSTEXPR
1597 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1600 iterator __cur =
begin();
1601 for (; __first != __last && __cur !=
end(); ++__cur, (void)++__first)
1603 if (__first == __last)
1604 _M_erase_at_end(__cur);
1609 template<
typename _ForwardIterator>
1610 _GLIBCXX20_CONSTEXPR
1612 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1617 _M_erase_at_end(std::copy(__first, __last,
begin()));
1620 _ForwardIterator __mid = __first;
1622 std::copy(__first, __mid,
begin());
1627#if __cplusplus < 201103L
1630 template<
typename _Integer>
1632 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
1634 { _M_fill_insert(__pos, __n, __x); }
1636 template<
typename _InputIterator>
1638 _M_insert_dispatch(iterator __pos,
1639 _InputIterator __first, _InputIterator __last,
1641 { _M_insert_range(__pos, __first, __last,
1645 _GLIBCXX20_CONSTEXPR
1647 _M_fill_insert(iterator __position, size_type __n,
bool __x);
1649 template<
typename _InputIterator>
1650 _GLIBCXX20_CONSTEXPR
1652 _M_insert_range(iterator __pos, _InputIterator __first,
1655 for (; __first != __last; ++__first)
1657 __pos =
insert(__pos, *__first);
1662 template<
typename _ForwardIterator>
1663 _GLIBCXX20_CONSTEXPR
1665 _M_insert_range(iterator __position, _ForwardIterator __first,
1668 _GLIBCXX20_CONSTEXPR
1670 _M_insert_aux(iterator __position,
bool __x);
1672 _GLIBCXX20_CONSTEXPR
1674 _M_check_len(size_type __n,
const char* __s)
const
1677 __throw_length_error(__N(__s));
1683 _GLIBCXX20_CONSTEXPR
1685 _M_erase_at_end(iterator __pos)
1686 { this->_M_impl._M_finish = __pos; }
1688 _GLIBCXX20_CONSTEXPR
1690 _M_erase(iterator __pos);
1692 _GLIBCXX20_CONSTEXPR
1694 _M_erase(iterator __first, iterator __last);
1702#if __cplusplus >= 201103L
1703 void data() =
delete;