Prevent moving from valid frames during defregmentation of MultiFrame

This commit is contained in:
János Benjamin Antal 2023-01-20 22:12:24 +01:00
parent 55b5d76092
commit 515a52130e

View File

@ -54,15 +54,17 @@ bool MultiFrame::HasInvalidFrame() const noexcept {
// NOLINTNEXTLINE (bugprone-exception-escape) // NOLINTNEXTLINE (bugprone-exception-escape)
void MultiFrame::DefragmentValidFrames() noexcept { void MultiFrame::DefragmentValidFrames() noexcept {
/* static constexpr auto kIsValid = [](const FrameWithValidity &frame) { return frame.IsValid(); };
from: https://en.cppreference.com/w/cpp/algorithm/remove static constexpr auto kIsInvalid = [](const FrameWithValidity &frame) { return !frame.IsValid(); };
"Removing is done by shifting (by means of copy assignment (until C++11)move assignment (since C++11)) the elements auto first_invalid_frame = std::find_if(frames_.begin(), frames_.end(), kIsInvalid);
in the range in such a way that the elements that are not to be removed appear in the beginning of the range. auto following_first_valid = std::find_if(first_invalid_frame, frames_.end(), kIsValid);
Relative order of the elements that remain is preserved and the physical size of the container is unchanged." while (first_invalid_frame != frames_.end() && following_first_valid != frames_.end()) {
*/ std::swap(*first_invalid_frame, *following_first_valid);
first_invalid_frame++;
// NOLINTNEXTLINE (bugprone-unused-return-value) first_invalid_frame = std::find_if(first_invalid_frame, frames_.end(), kIsInvalid);
std::remove_if(frames_.begin(), frames_.end(), [](auto &frame) { return !frame.IsValid(); }); following_first_valid++;
following_first_valid = std::find_if(following_first_valid, frames_.end(), kIsValid);
}
} }
ValidFramesReader MultiFrame::GetValidFramesReader() { return ValidFramesReader{*this}; } ValidFramesReader MultiFrame::GetValidFramesReader() { return ValidFramesReader{*this}; }