741 class vector<bool, _Alloc> :
protected _Bvector_base<_Alloc>
743 typedef _Bvector_base<_Alloc> _Base;
744 typedef typename _Base::_Bit_pointer _Bit_pointer;
745 typedef typename _Base::_Bit_alloc_traits _Bit_alloc_traits;
747#if __cplusplus >= 201103L
752 typedef bool value_type;
753 typedef size_t size_type;
754 typedef ptrdiff_t difference_type;
755 typedef _Bit_reference reference;
756 typedef bool const_reference;
757 typedef _Bit_reference* pointer;
758 typedef const bool* const_pointer;
759 typedef _Bit_iterator iterator;
760 typedef _Bit_const_iterator const_iterator;
763 typedef _Alloc allocator_type;
768 {
return _Base::get_allocator(); }
771 using _Base::_M_allocate;
772 using _Base::_M_deallocate;
773 using _Base::_S_nword;
774 using _Base::_M_get_Bit_allocator;
777#if __cplusplus >= 201103L
785 vector(
const allocator_type& __a)
788#if __cplusplus >= 201103L
791 vector(size_type __n,
const allocator_type& __a = allocator_type())
796 vector(size_type __n,
const bool& __value,
797 const allocator_type& __a = allocator_type())
800 vector(size_type __n,
const bool& __value =
bool(),
801 const allocator_type& __a = allocator_type())
805 _M_check_and_initialize(__n);
806 _M_initialize_value(__value);
811 : _Base(_Bit_alloc_traits::_S_select_on_copy(__x._M_get_Bit_allocator()))
813 const_iterator __xbegin = __x.
begin(), __xend = __x.
end();
814 _M_initialize(__x.
size());
815 _M_copy_aligned(__xbegin, __xend,
begin());
818#if __cplusplus >= 201103L
819 vector(vector&&) =
default;
835 _M_initialize(__x.
size());
836 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
843 vector(vector&& __x,
const __type_identity_t<allocator_type>& __a)
844 noexcept(_Bit_alloc_traits::_S_always_equal())
850 vector(
const vector& __x,
const __type_identity_t<allocator_type>& __a)
853 _M_initialize(__x.
size());
854 _M_copy_aligned(__x.
begin(), __x.
end(), begin());
859 const allocator_type& __a = allocator_type())
862 _M_initialize_range(__l.begin(), __l.end(),
867#if __cplusplus >= 201103L
868 template<
typename _InputIterator,
869 typename = std::_RequireInputIter<_InputIterator>>
871 vector(_InputIterator __first, _InputIterator __last,
872 const allocator_type& __a = allocator_type())
875 _M_initialize_range(__first, __last,
879 template<
typename _InputIterator>
880 vector(_InputIterator __first, _InputIterator __last,
881 const allocator_type& __a = allocator_type())
885 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
886 _M_initialize_dispatch(__first, __last, _Integral());
891 ~vector() _GLIBCXX_NOEXCEPT { }
899#if __cplusplus >= 201103L
900 if (_Bit_alloc_traits::_S_propagate_on_copy_assign())
902 if (this->_M_get_Bit_allocator() != __x._M_get_Bit_allocator())
904 this->_M_deallocate();
905 std::__alloc_on_copy(_M_get_Bit_allocator(),
906 __x._M_get_Bit_allocator());
907 _M_initialize(__x.
size());
910 std::__alloc_on_copy(_M_get_Bit_allocator(),
911 __x._M_get_Bit_allocator());
914 if (__x.
size() > capacity())
916 this->_M_deallocate();
917 _M_initialize(__x.
size());
919 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
924#if __cplusplus >= 201103L
927 operator=(vector&& __x)
noexcept(_Bit_alloc_traits::_S_nothrow_move())
929 if (_Bit_alloc_traits::_S_propagate_on_move_assign()
930 || this->_M_get_Bit_allocator() == __x._M_get_Bit_allocator())
932 this->_M_deallocate();
934 std::__alloc_on_move(_M_get_Bit_allocator(),
935 __x._M_get_Bit_allocator());
939 if (__x.
size() > capacity())
941 this->_M_deallocate();
942 _M_initialize(__x.
size());
944 this->_M_impl._M_finish = _M_copy_aligned(__x.
begin(), __x.
end(),
955 this->
assign(__l.begin(), __l.end());
966 assign(size_type __n,
const bool& __x)
967 { _M_fill_assign(__n, __x); }
969#if __cplusplus >= 201103L
970 template<
typename _InputIterator,
971 typename = std::_RequireInputIter<_InputIterator>>
974 assign(_InputIterator __first, _InputIterator __last)
977 template<
typename _InputIterator>
979 assign(_InputIterator __first, _InputIterator __last)
982 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
983 _M_assign_dispatch(__first, __last, _Integral());
987#if __cplusplus >= 201103L
994 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
996 begin() _GLIBCXX_NOEXCEPT
997 {
return iterator(this->_M_impl._M_start._M_p, 0); }
999 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1001 begin()
const _GLIBCXX_NOEXCEPT
1002 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
1004 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1006 end() _GLIBCXX_NOEXCEPT
1007 {
return this->_M_impl._M_finish; }
1009 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1011 end()
const _GLIBCXX_NOEXCEPT
1012 {
return this->_M_impl._M_finish; }
1014 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1016 rbegin() _GLIBCXX_NOEXCEPT
1017 {
return reverse_iterator(
end()); }
1019 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1020 const_reverse_iterator
1021 rbegin()
const _GLIBCXX_NOEXCEPT
1022 {
return const_reverse_iterator(
end()); }
1024 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1026 rend() _GLIBCXX_NOEXCEPT
1027 {
return reverse_iterator(
begin()); }
1029 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1030 const_reverse_iterator
1031 rend()
const _GLIBCXX_NOEXCEPT
1032 {
return const_reverse_iterator(
begin()); }
1034#if __cplusplus >= 201103L
1035 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1038 {
return const_iterator(this->_M_impl._M_start._M_p, 0); }
1040 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1042 cend()
const noexcept
1043 {
return this->_M_impl._M_finish; }
1045 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1046 const_reverse_iterator
1048 {
return const_reverse_iterator(
end()); }
1050 [[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1051 const_reverse_iterator
1052 crend()
const noexcept
1053 {
return const_reverse_iterator(
begin()); }
1056 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1058 size()
const _GLIBCXX_NOEXCEPT
1059 {
return size_type(
end() -
begin()); }
1061 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1065 const size_type __isize =
1066 __gnu_cxx::__numeric_traits<difference_type>::__max
1067 - int(_S_word_bit) + 1;
1068 const size_type __asize
1070 return (__asize <= __isize /
int(_S_word_bit)
1071 ? __asize *
int(_S_word_bit) : __isize);
1074 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1077 {
return size_type(const_iterator(this->_M_impl._M_end_addr(), 0)
1080 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1082 empty()
const _GLIBCXX_NOEXCEPT
1085 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1088 {
return begin()[__n]; }
1090 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1093 {
return begin()[__n]; }
1096 _GLIBCXX20_CONSTEXPR
1100 if (__n >= this->
size())
1101 __throw_out_of_range_fmt(__N(
"vector<bool>::_M_range_check: __n "
1102 "(which is %zu) >= this->size() "
1108 _GLIBCXX20_CONSTEXPR
1113 return (*
this)[__n];
1116 _GLIBCXX20_CONSTEXPR
1118 at(size_type __n)
const
1121 return (*
this)[__n];
1124 _GLIBCXX20_CONSTEXPR
1129 __throw_length_error(__N(
"vector::reserve"));
1134 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1137 {
return *
begin(); }
1139 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1142 {
return *
begin(); }
1144 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1147 {
return *(
end() - 1); }
1149 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
1152 {
return *(
end() - 1); }
1154 _GLIBCXX20_CONSTEXPR
1158 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr())
1159 *this->_M_impl._M_finish++ = __x;
1161 _M_insert_aux(
end(), __x);
1164 _GLIBCXX20_CONSTEXPR
1166 swap(vector& __x) _GLIBCXX_NOEXCEPT
1168#if __cplusplus >= 201103L
1169 __glibcxx_assert(_Bit_alloc_traits::propagate_on_container_swap::value
1170 || _M_get_Bit_allocator() == __x._M_get_Bit_allocator());
1172 this->_M_impl._M_swap_data(__x._M_impl);
1173 _Bit_alloc_traits::_S_on_swap(_M_get_Bit_allocator(),
1174 __x._M_get_Bit_allocator());
1178 _GLIBCXX20_CONSTEXPR
1180 swap(reference __x, reference __y) _GLIBCXX_NOEXCEPT
1187 _GLIBCXX20_CONSTEXPR
1189#if __cplusplus >= 201103L
1190 insert(const_iterator __position,
const bool& __x)
1192 insert(iterator __position,
const bool& __x)
1195 const difference_type __n = __position -
begin();
1196 if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()
1197 && __position == end())
1198 *this->_M_impl._M_finish++ = __x;
1200 _M_insert_aux(__position._M_const_cast(), __x);
1201 return begin() + __n;
1204#if _GLIBCXX_USE_DEPRECATED
1205 _GLIBCXX_DEPRECATED_SUGGEST(
"insert(position, false)")
1207 insert(const_iterator __position)
1208 {
return this->
insert(__position._M_const_cast(),
false); }
1211#if __cplusplus >= 201103L
1212 template<
typename _InputIterator,
1213 typename = std::_RequireInputIter<_InputIterator>>
1214 _GLIBCXX20_CONSTEXPR
1216 insert(const_iterator __position,
1217 _InputIterator __first, _InputIterator __last)
1219 difference_type __offset = __position -
cbegin();
1220 _M_insert_range(__position._M_const_cast(),
1223 return begin() + __offset;
1226 template<
typename _InputIterator>
1228 insert(iterator __position,
1229 _InputIterator __first, _InputIterator __last)
1232 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1233 _M_insert_dispatch(__position, __first, __last, _Integral());
1237#if __cplusplus >= 201103L
1238 _GLIBCXX20_CONSTEXPR
1240 insert(const_iterator __position, size_type __n,
const bool& __x)
1242 difference_type __offset = __position -
cbegin();
1243 _M_fill_insert(__position._M_const_cast(), __n, __x);
1244 return begin() + __offset;
1248 insert(iterator __position, size_type __n,
const bool& __x)
1249 { _M_fill_insert(__position, __n, __x); }
1252#if __cplusplus >= 201103L
1253 _GLIBCXX20_CONSTEXPR
1256 {
return this->
insert(__p, __l.begin(), __l.end()); }
1259 _GLIBCXX20_CONSTEXPR
1262 { --this->_M_impl._M_finish; }
1264 _GLIBCXX20_CONSTEXPR
1266#if __cplusplus >= 201103L
1267 erase(const_iterator __position)
1269 erase(iterator __position)
1271 {
return _M_erase(__position._M_const_cast()); }
1273 _GLIBCXX20_CONSTEXPR
1275#if __cplusplus >= 201103L
1276 erase(const_iterator __first, const_iterator __last)
1278 erase(iterator __first, iterator __last)
1280 {
return _M_erase(__first._M_const_cast(), __last._M_const_cast()); }
1282 _GLIBCXX20_CONSTEXPR
1284 resize(size_type __new_size,
bool __x =
bool())
1286 if (__new_size <
size())
1287 _M_erase_at_end(
begin() + difference_type(__new_size));
1292#if __cplusplus >= 201103L
1293 _GLIBCXX20_CONSTEXPR
1296 { _M_shrink_to_fit(); }
1299 _GLIBCXX20_CONSTEXPR
1301 flip() _GLIBCXX_NOEXCEPT
1303 _Bit_type *
const __end = this->_M_impl._M_end_addr();
1304 for (_Bit_type * __p = this->_M_impl._M_start._M_p; __p != __end; ++__p)
1308 _GLIBCXX20_CONSTEXPR
1310 clear() _GLIBCXX_NOEXCEPT
1311 { _M_erase_at_end(
begin()); }
1313#if __cplusplus >= 201103L
1314 template<
typename... _Args>
1315#if __cplusplus > 201402L
1316 _GLIBCXX20_CONSTEXPR
1321 emplace_back(_Args&&... __args)
1324#if __cplusplus > 201402L
1329 template<
typename... _Args>
1330 _GLIBCXX20_CONSTEXPR
1332 emplace(const_iterator __pos, _Args&&... __args)
1338 _GLIBCXX20_CONSTEXPR
1340 _M_copy_aligned(const_iterator __first, const_iterator __last,
1343 _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p);
1344 return std::copy(const_iterator(__last._M_p, 0), __last,
1348 _GLIBCXX20_CONSTEXPR
1350 _M_initialize(size_type __n)
1353 _GLIBCXX_DEBUG_ASSERT(__n <= (
size_t)-_S_word_bit);
1357 _Bit_pointer __q = this->_M_allocate(__n);
1358 this->_M_impl._M_end_of_storage = __q + _S_nword(__n);
1360 this->_M_impl._M_start = __start;
1361 this->_M_impl._M_finish = __start + difference_type(__n);
1365 template<
typename _SizeT>
1366 _GLIBCXX20_CONSTEXPR
1368 _M_check_and_initialize(_SizeT __n)
1371 __throw_length_error(
1372 __N(
"Cannot create std::vector<bool> larger than max_size()"));
1373 _M_initialize(
static_cast<size_type
>(__n));
1376 _GLIBCXX20_CONSTEXPR
1378 _M_initialize_value(
bool __x) _GLIBCXX_NOEXCEPT
1380 if (_Bit_type* __p = this->_M_impl._M_start._M_p)
1381 __fill_bvector_n(__p, this->_M_impl._M_end_addr() - __p, __x);
1384 _GLIBCXX20_CONSTEXPR
1386 _M_reallocate(size_type __n);
1388#if __cplusplus >= 201103L
1389 _GLIBCXX20_CONSTEXPR
1394#if __cplusplus < 201103L
1397 template<
typename _Integer>
1399 _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1401 _M_check_and_initialize(
static_cast<size_type
>(__n));
1402 _M_initialize_value(__x);
1405 template<
typename _InputIterator>
1407 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1409 { _M_initialize_range(__first, __last,
1413 template<
typename _InputIterator>
1414 _GLIBCXX20_CONSTEXPR
1416 _M_initialize_range(_InputIterator __first, _InputIterator __last,
1419 for (; __first != __last; ++__first)
1423 template<
typename _ForwardIterator>
1424 _GLIBCXX20_CONSTEXPR
1426 _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
1430 std::copy(__first, __last,
begin());
1433#if __cplusplus < 201103L
1436 template<
typename _Integer>
1438 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1439 { _M_fill_assign(__n, __val); }
1441 template<
class _InputIterator>
1443 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1448 _GLIBCXX20_CONSTEXPR
1450 _M_fill_assign(
size_t __n,
bool __x)
1454 _M_initialize_value(__x);
1459 _M_erase_at_end(
begin() + __n);
1460 _M_initialize_value(__x);
1464 template<
typename _InputIterator>
1465 _GLIBCXX20_CONSTEXPR
1467 _M_assign_aux(_InputIterator __first, _InputIterator __last,
1470 iterator __cur =
begin();
1471 for (; __first != __last && __cur !=
end(); ++__cur, (void)++__first)
1473 if (__first == __last)
1474 _M_erase_at_end(__cur);
1479 template<
typename _ForwardIterator>
1480 _GLIBCXX20_CONSTEXPR
1482 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1487 _M_erase_at_end(std::copy(__first, __last,
begin()));
1490 _ForwardIterator __mid = __first;
1492 std::copy(__first, __mid,
begin());
1497#if __cplusplus < 201103L
1500 template<
typename _Integer>
1502 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
1504 { _M_fill_insert(__pos, __n, __x); }
1506 template<
typename _InputIterator>
1508 _M_insert_dispatch(iterator __pos,
1509 _InputIterator __first, _InputIterator __last,
1511 { _M_insert_range(__pos, __first, __last,
1515 _GLIBCXX20_CONSTEXPR
1517 _M_fill_insert(iterator __position, size_type __n,
bool __x);
1519 template<
typename _InputIterator>
1520 _GLIBCXX20_CONSTEXPR
1522 _M_insert_range(iterator __pos, _InputIterator __first,
1525 for (; __first != __last; ++__first)
1527 __pos =
insert(__pos, *__first);
1532 template<
typename _ForwardIterator>
1533 _GLIBCXX20_CONSTEXPR
1535 _M_insert_range(iterator __position, _ForwardIterator __first,
1538 _GLIBCXX20_CONSTEXPR
1540 _M_insert_aux(iterator __position,
bool __x);
1542 _GLIBCXX20_CONSTEXPR
1544 _M_check_len(size_type __n,
const char* __s)
const
1547 __throw_length_error(__N(__s));
1553 _GLIBCXX20_CONSTEXPR
1555 _M_erase_at_end(iterator __pos)
1556 { this->_M_impl._M_finish = __pos; }
1558 _GLIBCXX20_CONSTEXPR
1560 _M_erase(iterator __pos);
1562 _GLIBCXX20_CONSTEXPR
1564 _M_erase(iterator __first, iterator __last);
1572#if __cplusplus >= 201103L
1573 void data() =
delete;