1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 08:52:40 +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

@@ -2454,7 +2454,7 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
IConsolePrint(CC_INFO, "Loaded GRF files:");
int i = 1;
for (GRFFile *grf : files) {
auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](NewGRFProfiler &pr) { return pr.grffile == grf; });
auto profiler = std::ranges::find(_newgrf_profilers, grf, &NewGRFProfiler::grffile);
bool selected = profiler != _newgrf_profilers.end();
bool active = selected && profiler->active;
TextColour tc = active ? TC_LIGHT_BLUE : selected ? TC_GREEN : CC_INFO;
@@ -2496,8 +2496,7 @@ DEF_CONSOLE_CMD(ConNewGRFProfile)
continue;
}
GRFFile *grf = files[grfnum - 1];
auto pos = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](NewGRFProfiler &pr) { return pr.grffile == grf; });
if (pos != _newgrf_profilers.end()) _newgrf_profilers.erase(pos);
_newgrf_profilers.erase(std::ranges::find(_newgrf_profilers, grf, &NewGRFProfiler::grffile));
}
return true;
}