1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-22 11:44:17 +01:00

Codechange: Use projection-based std::range::find where possible.

This simplifies matching by class members and avoids wordy lambdas.
This commit is contained in:
Peter Nelson
2024-11-10 10:56:37 +00:00
committed by Peter Nelson
parent 876d53282e
commit 059a4b22f7
16 changed files with 31 additions and 44 deletions

View File

@@ -388,7 +388,7 @@ void Station::AddIndustryToDeliver(Industry *ind, TileIndex tile)
uint distance = DistanceMax(this->xy, tile);
/* Don't check further if this industry is already in the list but update the distance if it's closer */
auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
auto pos = std::ranges::find(this->industries_near, ind, &IndustryListEntry::industry);
if (pos != this->industries_near.end()) {
if (pos->distance > distance) {
auto node = this->industries_near.extract(pos);
@@ -410,7 +410,7 @@ void Station::AddIndustryToDeliver(Industry *ind, TileIndex tile)
*/
void Station::RemoveIndustryToDeliver(Industry *ind)
{
auto pos = std::find_if(this->industries_near.begin(), this->industries_near.end(), [&](const IndustryListEntry &e) { return e.industry->index == ind->index; });
auto pos = std::ranges::find(this->industries_near, ind, &IndustryListEntry::industry);
if (pos != this->industries_near.end()) {
this->industries_near.erase(pos);
}