mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::ranges::count(_if).
parent
3be0166801
commit
876d53282e
|
@ -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; });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; });
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue