Skip to content

Commit

Permalink
[container] Fix reducing capacity to 0 on DynamicArray::clear()
Browse files Browse the repository at this point in the history
Calling shrink_to_fit() on a std::vector in libstdc++ is a no-op with
exceptions disabled. This fix applies the "vector swap trick" to make
it work even when compiling with -fno-exceptions.
  • Loading branch information
chris-durand authored and salkinium committed Nov 12, 2024
1 parent 678fd9a commit 7b571a6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/modm/container/dynamic_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ namespace modm
clear()
{
data_.clear();
data_.shrink_to_fit();
// shrink vector to zero capacity
// shrink_to_fit() is a no-op with exceptions disabled
std::vector(data_).swap(data_);
}

/**
Expand Down

0 comments on commit 7b571a6

Please sign in to comment.