1
0
Fork 0

Codechange: Use std::ranges::count(_if).

pull/13119/head
Peter Nelson 2024-11-10 10:53:52 +00:00 committed by Peter Nelson
parent 3be0166801
commit 876d53282e
7 changed files with 10 additions and 10 deletions

View File

@ -128,7 +128,7 @@ struct CargoArray : std::array<uint, NUM_CARGO> {
*/
inline uint GetCount() const
{
return std::count_if(this->begin(), this->end(), [](uint amount) { return amount != 0; });
return std::ranges::count_if(*this, [](uint amount) { return amount != 0; });
}
};

View File

@ -2617,8 +2617,8 @@ struct IndustryCargoesWindow : public Window {
const IndustrySpec *indsp = GetIndustrySpec(it);
if (!indsp->enabled) continue;
this->ind_textsize = maxdim(this->ind_textsize, GetStringBoundingBox(indsp->name));
CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(std::begin(indsp->accepts_cargo), std::end(indsp->accepts_cargo), IsValidCargoID));
CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::count_if(std::begin(indsp->produced_cargo), std::end(indsp->produced_cargo), IsValidCargoID));
CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::ranges::count_if(indsp->accepts_cargo, IsValidCargoID));
CargoesField::max_cargoes = std::max<uint>(CargoesField::max_cargoes, std::ranges::count_if(indsp->produced_cargo, IsValidCargoID));
}
d.width = std::max(d.width, this->ind_textsize.width);
d.height = this->ind_textsize.height;

View File

@ -102,7 +102,7 @@ uint NewGRFClass<Tspec, Tindex, Tmax>::GetClassCount()
template <typename Tspec, typename Tindex, Tindex Tmax>
uint NewGRFClass<Tspec, Tindex, Tmax>::GetUIClassCount()
{
return std::count_if(std::begin(NewGRFClass::classes), std::end(NewGRFClass::classes), [](const auto &cls) { return cls.GetUISpecCount() > 0; });
return std::ranges::count_if(NewGRFClass::classes, [](const auto &cls) { return cls.GetUISpecCount() > 0; });
}
/**

View File

@ -472,7 +472,7 @@ static INT_PTR CALLBACK CrashDialogFunc(HWND wnd, UINT msg, WPARAM wParam, LPARA
std::string crashlog = CrashLogWindows::current->survey.dump(4);
size_t crashlog_length = crashlog.size() + 1;
/* Reserve extra space for LF to CRLF conversion. */
crashlog_length += std::count(crashlog.begin(), crashlog.end(), '\n');
crashlog_length += std::ranges::count(crashlog, '\n');
const size_t filename_count = 4;
const size_t filename_buf_length = MAX_PATH + 1;

View File

@ -985,7 +985,7 @@ public:
bool HasClassChoice() const override
{
return std::count_if(std::begin(StationClass::Classes()), std::end(StationClass::Classes()), std::not_fn(IsWaypointClass)) > 1;
return std::ranges::count_if(StationClass::Classes(), std::not_fn(IsWaypointClass)) > 1;
}
int GetSelectedClass() const override { return _station_gui.sel_class; }
@ -1796,7 +1796,7 @@ public:
bool HasClassChoice() const override
{
return std::count_if(std::begin(StationClass::Classes()), std::end(StationClass::Classes()), IsWaypointClass) > 1;
return std::ranges::count_if(StationClass::Classes(), IsWaypointClass) > 1;
}
void Close(int) override { ResetObjectToPlace(); }

View File

@ -1204,7 +1204,7 @@ public:
bool HasClassChoice() const override
{
return std::count_if(std::begin(RoadStopClass::Classes()), std::end(RoadStopClass::Classes()), IsClassChoice);
return std::ranges::count_if(RoadStopClass::Classes(), IsClassChoice);
}
int GetSelectedClass() const override { return _roadstop_gui.sel_class; }
@ -1614,7 +1614,7 @@ public:
bool HasClassChoice() const override
{
return std::count_if(std::begin(RoadStopClass::Classes()), std::end(RoadStopClass::Classes()), IsWaypointClass) > 1;
return std::ranges::count_if(RoadStopClass::Classes(), IsWaypointClass) > 1;
}
void Close(int) override { ResetObjectToPlace(); }

View File

@ -387,7 +387,7 @@ bool FindSubsidyIndustryCargoRoute()
CargoID cid;
/* Randomize cargo type */
int num_cargos = std::count_if(std::begin(src_ind->produced), std::end(src_ind->produced), [](const auto &p) { return IsValidCargoID(p.cargo); });
int num_cargos = std::ranges::count_if(src_ind->produced, [](const auto &p) { return IsValidCargoID(p.cargo); });
if (num_cargos == 0) return false; // industry produces nothing
int cargo_num = RandomRange(num_cargos) + 1;