Using std::erase for pellets possible in C++20
This commit is contained in:
parent
55fbb53591
commit
b79b2a29e8
2 changed files with 2 additions and 10 deletions
|
@ -7,11 +7,7 @@ Pellets::Pellets()
|
||||||
: positions(initialPelletPositions()) {}
|
: positions(initialPelletPositions()) {}
|
||||||
|
|
||||||
bool Pellets::eatPelletAtPosition(GridPosition p) {
|
bool Pellets::eatPelletAtPosition(GridPosition p) {
|
||||||
auto it = std::find(positions.begin(), positions.end(), p);
|
return std::erase(positions, p) > 0;
|
||||||
if (it == positions.end())
|
|
||||||
return false;
|
|
||||||
positions.erase(it);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pacman
|
} // namespace pacman
|
||||||
|
|
|
@ -7,11 +7,7 @@ SuperPellets::SuperPellets()
|
||||||
: positions(initialSuperPelletPositions()) {}
|
: positions(initialSuperPelletPositions()) {}
|
||||||
|
|
||||||
bool SuperPellets::eatPelletAtPosition(GridPosition p) {
|
bool SuperPellets::eatPelletAtPosition(GridPosition p) {
|
||||||
auto it = std::find(positions.begin(), positions.end(), p);
|
return std::erase(positions, p) > 0;
|
||||||
if (it == positions.end())
|
|
||||||
return false;
|
|
||||||
positions.erase(it);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace pacman
|
} // namespace pacman
|
||||||
|
|
Loading…
Reference in a new issue