Using std::erase for pellets possible in C++20

This commit is contained in:
Ólafur Waage 2021-09-08 10:21:37 +02:00
parent 55fbb53591
commit b79b2a29e8
2 changed files with 2 additions and 10 deletions

View file

@ -7,11 +7,7 @@ Pellets::Pellets()
: positions(initialPelletPositions()) {}
bool Pellets::eatPelletAtPosition(GridPosition p) {
auto it = std::find(positions.begin(), positions.end(), p);
if (it == positions.end())
return false;
positions.erase(it);
return true;
return std::erase(positions, p) > 0;
}
} // namespace pacman

View file

@ -7,11 +7,7 @@ SuperPellets::SuperPellets()
: positions(initialSuperPelletPositions()) {}
bool SuperPellets::eatPelletAtPosition(GridPosition p) {
auto it = std::find(positions.begin(), positions.end(), p);
if (it == positions.end())
return false;
positions.erase(it);
return true;
return std::erase(positions, p) > 0;
}
} // namespace pacman