704 class vector<bool, _Alloc> :
protected _Bvector_base<_Alloc>
706 typedef _Bvector_base<_Alloc> _Base;
707 typedef typename _Base::_Bit_pointer _Bit_pointer;
710#if __cplusplus >= 201103L
715 typedef bool value_type;
716 typedef size_t size_type;
717 typedef ptrdiff_t difference_type;
718 typedef _Bit_reference reference;
719 typedef bool const_reference;
720 typedef _Bit_reference* pointer;
721 typedef const bool* const_pointer;
722 typedef _Bit_iterator iterator;
723 typedef _Bit_const_iterator const_iterator;
726 typedef _Alloc allocator_type;
731 {
return _Base::get_allocator(); }
734 using _Base::_M_allocate;
735 using _Base::_M_deallocate;
736 using _Base::_S_nword;
737 using _Base::_M_get_Bit_allocator;
740#if __cplusplus >= 201103L
748 vector(
const allocator_type& __a)
751#if __cplusplus >= 201103L
754 vector(size_type __n,
const allocator_type& __a = allocator_type())
759 vector(size_type __n,
const bool& __value,
760 const allocator_type& __a = allocator_type())
763 vector(size_type __n,
const bool& __value =
bool(),
764 const allocator_type& __a = allocator_type())
769 _M_initialize_value(__value);
774 : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator()))
776 const_iterator __xbegin = __x.
begin(), __xend = __x.
end();
777 _M_initialize(__x.
size());
778 _M_copy_aligned(__xbegin, __xend,
begin());
781#if __cplusplus >= 201103L
798 _M_initialize(__x.
size());
806 vector(
vector&& __x,
const __type_identity_t<allocator_type>& __a)
807 noexcept(_Bit_alloc_traits::_S_always_equal())
813 vector(
const vector& __x,
const __type_identity_t<allocator_type>& __a)
816 _M_initialize(__x.
size());
822 const allocator_type& __a = allocator_type())
825 _M_initialize_range(__l.begin(), __l.end(),
830#if __cplusplus >= 201103L
831 template<
typename _InputIterator,
832 typename = std::_RequireInputIter<_InputIterator>>
834 vector(_InputIterator __first, _InputIterator __last,
835 const allocator_type& __a = allocator_type())
838 _M_initialize_range(__first, __last,
842 template<
typename _InputIterator>
843 vector(_InputIterator __first, _InputIterator __last,
844 const allocator_type& __a = allocator_type())
848 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
849 _M_initialize_dispatch(__first, __last, _Integral());
854 ~vector() _GLIBCXX_NOEXCEPT { }
862#if __cplusplus >= 201103L
863 if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
865 if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
867 this->_M_deallocate();
868 std::__alloc_on_copy(_M_get_Bit_allocator(),
869 __x._M_get_Bit_allocator());
870 _M_initialize(__x.
size());
873 std::__alloc_on_copy(_M_get_Bit_allocator(),
874 __x._M_get_Bit_allocator());
879 this->_M_deallocate();
880 _M_initialize(__x.
size());
882 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
887#if __cplusplus >= 201103L
892 if (_Bit_alloc_traits::_S_propagate_on_move_assign()
893 || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
895 this->_M_deallocate();
897 std::__alloc_on_move(_M_get_Bit_allocator(),
898 __x._M_get_Bit_allocator());
904 this->_M_deallocate();
905 _M_initialize(__x.
size());
907 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
918 this->
assign(__l.begin(), __l.end());
929 assign(size_type __n,
const bool& __x)
930 { _M_fill_assign(__n, __x); }
932#if __cplusplus >= 201103L
933 template<
typename _InputIterator,
934 typename = std::_RequireInputIter<_InputIterator>>
937 assign(_InputIterator __first, _InputIterator __last)
940 template<
typename _InputIterator>
942 assign(_InputIterator __first, _InputIterator __last)
945 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
946 _M_assign_dispatch(__first, __last, _Integral());
950#if __cplusplus >= 201103L
957 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
959 begin() _GLIBCXX_NOEXCEPT
960 {
return iterator(this->_M_impl._M_start._M_p, 0); }
962 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
964 begin()
const _GLIBCXX_NOEXCEPT
965 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
967 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
969 end() _GLIBCXX_NOEXCEPT
970 {
return this->_M_impl._M_finish; }
972 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
974 end()
const _GLIBCXX_NOEXCEPT
975 {
return this->_M_impl._M_finish; }
977 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
979 rbegin() _GLIBCXX_NOEXCEPT
982 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
984 rbegin()
const _GLIBCXX_NOEXCEPT
987 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
989 rend() _GLIBCXX_NOEXCEPT
992 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
994 rend()
const _GLIBCXX_NOEXCEPT
997#if __cplusplus >= 201103L
998 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1001 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
1003 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1005 cend()
const noexcept
1006 {
return this->_M_impl._M_finish; }
1008 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1013 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1015 crend()
const noexcept
1019 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1021 size()
const _GLIBCXX_NOEXCEPT
1022 {
return size_type(
end() -
begin()); }
1024 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1028 const size_type __isize =
1029 __gnu_cxx::__numeric_traits<difference_type>::__max
1030 - int(_S_word_bit) + 1;
1031 const size_type __asize
1032 = _Bit_alloc_traits::max_size(_M_get_Bit_allocator());
1033 return (__asize <= __isize /
int(_S_word_bit)
1034 ? __asize *
int(_S_word_bit) : __isize);
1037 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1040 {
return size_type(const_iterator(this->_M_impl._M_end_addr(), 0)
1043 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1045 empty()
const _GLIBCXX_NOEXCEPT
1048 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1051 {
return begin()[__n]; }
1053 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1056 {
return begin()[__n]; }
1059 _GLIBCXX20_CONSTEXPR
1063 if (__n >= this->
size())
1064 __throw_out_of_range_fmt(__N(
"vector<bool>::_M_range_check: __n "
1065 "(which is %zu) >= this->size() "
1071 _GLIBCXX20_CONSTEXPR
1076 return (*
this)[__n];
1079 _GLIBCXX20_CONSTEXPR
1081 at(size_type __n)
const
1084 return (*
this)[__n];
1087 _GLIBCXX20_CONSTEXPR
1092 __throw_length_error(__N(
"vector::reserve"));
1097 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1100 {
return *
begin(); }
1102 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1105 {
return *
begin(); }
1107 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1110 {
return *(
end() - 1); }
1112 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1115 {
return *(
end() - 1); }
1117 _GLIBCXX20_CONSTEXPR
1121 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1122 *this->_M_impl._M_finish++ = __x;
1124 _M_insert_aux(
end(), __x);
1127 _GLIBCXX20_CONSTEXPR
1129 swap(
vector& __x) _GLIBCXX_NOEXCEPT
1131#if __cplusplus >= 201103L
1132 __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value
1133 || _M_get_Bit_allocator() == __x._M_get_Bit_allocator());
1135 this->_M_impl._M_swap_data(__x._M_impl);
1136 _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(),
1137 __x._M_get_Bit_allocator());
1141 _GLIBCXX20_CONSTEXPR
1143 swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT
1150 _GLIBCXX20_CONSTEXPR
1152#if __cplusplus >= 201103L
1153 insert(const_iterator __position,
const bool& __x)
1155 insert(iterator __position,
const bool& __x)
1158 const difference_type __n = __position -
begin();
1159 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()
1160 && __position ==
end())
1161 *this->_M_impl._M_finish++ = __x;
1163 _M_insert_aux(__position._M_const_cast(), __x);
1164 return begin() + __n;
1167#if _GLIBCXX_USE_DEPRECATED
1168 _GLIBCXX_DEPRECATED_SUGGEST(
"insert(position, false)")
1170 insert(const_iterator __position)
1171 {
return this->
insert(__position._M_const_cast(),
false); }
1174#if __cplusplus >= 201103L
1175 template<
typename _InputIterator,
1176 typename = std::_RequireInputIter<_InputIterator>>
1177 _GLIBCXX20_CONSTEXPR
1179 insert(const_iterator __position,
1180 _InputIterator __first, _InputIterator __last)
1182 difference_type __offset = __position -
cbegin();
1183 _M_insert_range(__position._M_const_cast(),
1186 return begin() + __offset;
1189 template<
typename _InputIterator>
1191 insert(iterator __position,
1192 _InputIterator __first, _InputIterator __last)
1195 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1196 _M_insert_dispatch(__position, __first, __last, _Integral());
1200#if __cplusplus >= 201103L
1201 _GLIBCXX20_CONSTEXPR
1203 insert(const_iterator __position, size_type __n,
const bool& __x)
1205 difference_type __offset = __position -
cbegin();
1206 _M_fill_insert(__position._M_const_cast(), __n, __x);
1207 return begin() + __offset;
1211 insert(iterator __position, size_type __n,
const bool& __x)
1212 { _M_fill_insert(__position, __n, __x); }
1215#if __cplusplus >= 201103L
1216 _GLIBCXX20_CONSTEXPR
1219 {
return this->
insert(__p, __l.begin(), __l.end()); }
1222 _GLIBCXX20_CONSTEXPR
1225 { --this->_M_impl._M_finish; }
1227 _GLIBCXX20_CONSTEXPR
1229#if __cplusplus >= 201103L
1230 erase(const_iterator __position)
1232 erase(iterator __position)
1234 {
return _M_erase(__position._M_const_cast()); }
1236 _GLIBCXX20_CONSTEXPR
1238#if __cplusplus >= 201103L
1239 erase(const_iterator __first, const_iterator __last)
1241 erase(iterator __first, iterator __last)
1243 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1245 _GLIBCXX20_CONSTEXPR
1247 resize(size_type __new_size,
bool __x =
bool())
1249 if (__new_size <
size())
1250 _M_erase_at_end(
begin() + difference_type(__new_size));
1255#if __cplusplus >= 201103L
1256 _GLIBCXX20_CONSTEXPR
1259 { _M_shrink_to_fit(); }
1262 _GLIBCXX20_CONSTEXPR
1264 flip() _GLIBCXX_NOEXCEPT
1266 _Bit_type *
const __end = this->_M_impl._M_end_addr();
1267 for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p)
1271 _GLIBCXX20_CONSTEXPR
1273 clear() _GLIBCXX_NOEXCEPT
1274 { _M_erase_at_end(
begin()); }
1276#if __cplusplus >= 201103L
1277 template<
typename... _Args>
1278#if __cplusplus > 201402L
1279 _GLIBCXX20_CONSTEXPR
1284 emplace_back(_Args&&... __args)
1287#if __cplusplus > 201402L
1292 template<
typename... _Args>
1293 _GLIBCXX20_CONSTEXPR
1295 emplace(const_iterator __pos, _Args&&... __args)
1296 {
return insert(__pos,
bool(__args...)); }
1301 _GLIBCXX20_CONSTEXPR
1303 _M_copy_aligned(const_iterator __first, const_iterator __last,
1306 _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
1307 return std::copy(const_iterator(__last._M_p, 0), __last,
1311 _GLIBCXX20_CONSTEXPR
1313 _M_initialize(size_type __n)
1317 _Bit_pointer __q = this->_M_allocate(__n);
1318 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1320 this->_M_impl._M_start = __start;
1321 this->_M_impl._M_finish = __start + difference_type(__n);
1325 _GLIBCXX20_CONSTEXPR
1327 _M_initialize_value(
bool __x) _GLIBCXX_NOEXCEPT
1329 if (_Bit_type* __p = this->_M_impl._M_start._M_p)
1330 __fill_bvector_n(__p, this->_M_impl._M_end_addr() - __p, __x);
1333 _GLIBCXX20_CONSTEXPR
1335 _M_reallocate(size_type __n);
1337#if __cplusplus >= 201103L
1338 _GLIBCXX20_CONSTEXPR
1343#if __cplusplus < 201103L
1346 template<
typename _Integer>
1348 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1350 _M_initialize(
static_cast<size_type
>(__n));
1351 _M_initialize_value(__x);
1354 template<
typename _InputIterator>
1356 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1358 { _M_initialize_range(__first, __last,
1362 template<
typename _InputIterator>
1363 _GLIBCXX20_CONSTEXPR
1365 _M_initialize_range(_InputIterator __first, _InputIterator __last,
1368 for (; __first != __last; ++__first)
1372 template<
typename _ForwardIterator>
1373 _GLIBCXX20_CONSTEXPR
1375 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
1380 std::copy(__first, __last,
begin());
1383#if __cplusplus < 201103L
1386 template<
typename _Integer>
1388 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1389 { _M_fill_assign(__n, __val); }
1391 template<
class _InputIterator>
1393 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1398 _GLIBCXX20_CONSTEXPR
1400 _M_fill_assign(
size_t __n,
bool __x)
1404 _M_initialize_value(__x);
1409 _M_erase_at_end(
begin() + __n);
1410 _M_initialize_value(__x);
1414 template<
typename _InputIterator>
1415 _GLIBCXX20_CONSTEXPR
1417 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1420 iterator __cur =
begin();
1421 for (; __first != __last && __cur !=
end(); ++__cur, (void)++__first)
1423 if (__first == __last)
1424 _M_erase_at_end(__cur);
1429 template<
typename _ForwardIterator>
1430 _GLIBCXX20_CONSTEXPR
1432 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1437 _M_erase_at_end(std::copy(__first, __last,
begin()));
1440 _ForwardIterator __mid = __first;
1442 std::copy(__first, __mid,
begin());
1447#if __cplusplus < 201103L
1450 template<
typename _Integer>
1452 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
1454 { _M_fill_insert(__pos, __n, __x); }
1456 template<
typename _InputIterator>
1458 _M_insert_dispatch(iterator __pos,
1459 _InputIterator __first, _InputIterator __last,
1461 { _M_insert_range(__pos, __first, __last,
1465 _GLIBCXX20_CONSTEXPR
1467 _M_fill_insert(iterator __position, size_type __n,
bool __x);
1469 template<
typename _InputIterator>
1470 _GLIBCXX20_CONSTEXPR
1472 _M_insert_range(iterator __pos, _InputIterator __first,
1475 for (; __first != __last; ++__first)
1477 __pos =
insert(__pos, *__first);
1482 template<
typename _ForwardIterator>
1483 _GLIBCXX20_CONSTEXPR
1485 _M_insert_range(iterator __position, _ForwardIterator __first,
1488 _GLIBCXX20_CONSTEXPR
1490 _M_insert_aux(iterator __position,
bool __x);
1492 _GLIBCXX20_CONSTEXPR
1494 _M_check_len(size_type __n,
const char* __s)
const
1497 __throw_length_error(__N(__s));
1503 _GLIBCXX20_CONSTEXPR
1505 _M_erase_at_end(iterator __pos)
1506 { this->_M_impl._M_finish = __pos; }
1508 _GLIBCXX20_CONSTEXPR
1510 _M_erase(iterator __pos);
1512 _GLIBCXX20_CONSTEXPR
1514 _M_erase(iterator __first, iterator __last);
1522#if __cplusplus >= 201103L
1523 void data() =
delete;