Skip to content

Commit

Permalink
Fix shrink_to_fit for vector<bool>
Browse files Browse the repository at this point in the history
  • Loading branch information
winner245 committed Dec 18, 2024
1 parent 79e859e commit 89af9e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libcxx/include/__vector/vector_bool.h
Original file line number Diff line number Diff line change
Expand Up @@ -841,11 +841,13 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::reserve(size_type _

template <class _Allocator>
_LIBCPP_CONSTEXPR_SINCE_CXX20 void vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT {
if (__external_cap_to_internal(size()) > __cap_) {
if (__external_cap_to_internal(size()) < __cap_) {
#if _LIBCPP_HAS_EXCEPTIONS
try {
#endif // _LIBCPP_HAS_EXCEPTIONS
vector(*this, allocator_type(__alloc_)).swap(*this);
vector __v(*this, allocator_type(__alloc_));
if (__v.__cap_ < __cap_)
__v.swap(*this);
#if _LIBCPP_HAS_EXCEPTIONS
} catch (...) {
}
Expand Down

0 comments on commit 89af9e2

Please sign in to comment.