Skip to content

Commit

Permalink
Simplified logic using stl algorithms
Browse files Browse the repository at this point in the history
Signed-off-by: Arjo Chakravarty <arjoc@google.com>
  • Loading branch information
arjo129 committed Jun 19, 2024
1 parent d6462a2 commit 24f539d
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/SystemManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,25 +441,7 @@ template<typename Tp>
void RemoveFromVectorIf(std::vector<Tp>& vec,
typename identity<std::function<bool(const Tp&)>>::type pred)
{
auto originalSize = vec.size();
int j = 0;

for(std::size_t i = 0; i < vec.size(); ++i)
{
if (pred(vec[i]))
{
j++;
}
else
{
vec[i-j] = vec[i];
}
}

while (vec.size() > originalSize - j)
{
vec.pop_back();
}
vec.erase(std::remove_if(vec.begin(), vec.end(), pred), vec.end());
}

//////////////////////////////////////////////////
Expand Down

0 comments on commit 24f539d

Please sign in to comment.