diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 446af68ae9..1f91ef8a90 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1353,7 +1353,7 @@ struct BuildVehicleWindow : Window { this->eng_list.Filter(this->cargo_filter_criteria); if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine this->SelectEngine(INVALID_ENGINE); - } else if (std::find(this->eng_list.begin(), this->eng_list.end(), this->sel_engine) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list + } else if (std::ranges::find(this->eng_list, this->sel_engine, &GUIEngineListItem::engine_id) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list this->SelectEngine(this->eng_list[0].engine_id); } } @@ -1426,7 +1426,7 @@ struct BuildVehicleWindow : Window { /* ensure primary engine of variant group is in list */ for (const auto &variant : variants) { - if (std::find(list.begin(), list.end(), variant) == list.end()) { + if (std::ranges::find(list, variant, &GUIEngineListItem::engine_id) == list.end()) { const Engine *e = Engine::Get(variant); list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0); if (e->u.rail.railveh_type != RAILVEH_WAGON) num_engines++; @@ -1568,7 +1568,7 @@ struct BuildVehicleWindow : Window { } for (const auto &variant : variants) { - if (std::find(this->eng_list.begin(), this->eng_list.end(), variant) == this->eng_list.end()) { + if (std::ranges::find(this->eng_list, variant, &GUIEngineListItem::engine_id) == this->eng_list.end()) { const Engine *e = Engine::Get(variant); this->eng_list.emplace_back(variant, e->info.variant_id, e->display_flags | EngineDisplayFlags::Shaded, 0); } diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 70d62e3285..42111748a0 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -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; } diff --git a/src/engine_gui.h b/src/engine_gui.h index 5e2d5fe336..49eb46710b 100644 --- a/src/engine_gui.h +++ b/src/engine_gui.h @@ -25,9 +25,6 @@ struct GUIEngineListItem { uint16_t level_mask; ///< Mask of level continuations. GUIEngineListItem(EngineID engine_id, EngineID variant_id, EngineDisplayFlags flags, uint8_t indent) : engine_id(engine_id), variant_id(variant_id), flags(flags), indent(indent), level_mask(0) {} - - /* Used when searching list only by engine_id. */ - bool operator == (const EngineID &other) const { return this->engine_id == other; } }; typedef GUIList GUIEngineList; diff --git a/src/group_gui.cpp b/src/group_gui.cpp index a48baead9b..cc24010cf2 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -1131,7 +1131,7 @@ public: if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) { const Group *g = Group::Get(g_id); - auto found = std::find_if(std::begin(this->groups), std::end(this->groups), [g](const auto &item) { return item.group == g; }); + auto found = std::ranges::find(this->groups, g, &GUIGroupListItem::group); if (found == std::end(this->groups)) { /* The group's branch is maybe collapsed, so try to expand it. */ for (auto pg = Group::GetIfValid(g->parent); pg != nullptr; pg = Group::GetIfValid(pg->parent)) { @@ -1140,7 +1140,7 @@ public: this->groups.ForceRebuild(); this->BuildGroupList(this->owner); this->group_sb->SetCount(this->groups.size()); - found = std::find_if(std::begin(this->groups), std::end(this->groups), [g](const auto &item) { return item.group == g; }); + found = std::ranges::find(this->groups, g, &GUIGroupListItem::group); } if (found != std::end(this->groups)) this->group_sb->ScrollTowards(std::distance(std::begin(this->groups), found)); } diff --git a/src/industry.h b/src/industry.h index 6dd1cf792a..b40b9c7c68 100644 --- a/src/industry.h +++ b/src/industry.h @@ -167,7 +167,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { inline ProducedCargoes::iterator GetCargoProduced(CargoID cargo) { if (!IsValidCargoID(cargo)) return std::end(this->produced); - return std::find_if(std::begin(this->produced), std::end(this->produced), [&cargo](const auto &p) { return p.cargo == cargo; }); + return std::ranges::find(this->produced, cargo, &ProducedCargo::cargo); } /** @@ -178,7 +178,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { inline ProducedCargoes::const_iterator GetCargoProduced(CargoID cargo) const { if (!IsValidCargoID(cargo)) return std::end(this->produced); - return std::find_if(std::begin(this->produced), std::end(this->produced), [&cargo](const auto &p) { return p.cargo == cargo; }); + return std::ranges::find(this->produced, cargo, &ProducedCargo::cargo); } /** @@ -189,7 +189,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { inline AcceptedCargoes::iterator GetCargoAccepted(CargoID cargo) { if (!IsValidCargoID(cargo)) return std::end(this->accepted); - return std::find_if(std::begin(this->accepted), std::end(this->accepted), [&cargo](const auto &a) { return a.cargo == cargo; }); + return std::ranges::find(this->accepted, cargo, &AcceptedCargo::cargo); } /** @@ -200,7 +200,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { inline AcceptedCargoes::const_iterator GetCargoAccepted(CargoID cargo) const { if (!IsValidCargoID(cargo)) return std::end(this->accepted); - return std::find_if(std::begin(this->accepted), std::end(this->accepted), [&cargo](const auto &a) { return a.cargo == cargo; }); + return std::ranges::find(this->accepted, cargo, &AcceptedCargo::cargo); } /** diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 473b6b57b0..ef584464bb 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1624,9 +1624,7 @@ protected: * because this is the one the player interested in, and that way it is not hidden in the 'n' more cargos */ const CargoID cid = this->produced_cargo_filter_criteria; if (cid != CargoFilterCriteria::CF_ANY && cid != CargoFilterCriteria::CF_NONE) { - auto filtered_ci = std::find_if(cargos.begin(), cargos.end(), [cid](const CargoInfo &ci) -> bool { - return ci.cargo_id == cid; - }); + auto filtered_ci = std::ranges::find(cargos, cid, &CargoInfo::cargo_id); if (filtered_ci != cargos.end()) { std::rotate(cargos.begin(), filtered_ci, filtered_ci + 1); } diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp index 54d5200115..18ee2655a5 100644 --- a/src/music/dmusic.cpp +++ b/src/music/dmusic.cpp @@ -70,11 +70,6 @@ struct DLSFile { WSMPL wave_sample; std::vector wave_loops; - - bool operator ==(long offset) const - { - return this->file_offset == offset; - } }; std::vector instruments; @@ -503,7 +498,7 @@ bool DLSFile::LoadFile(const std::string &file) /* Resolve wave pool table. */ for (std::vector::iterator cue = this->pool_cues.begin(); cue != this->pool_cues.end(); cue++) { - std::vector::iterator w = std::find(this->waves.begin(), this->waves.end(), cue->ulOffset); + std::vector::iterator w = std::ranges::find(this->waves, cue->ulOffset, &DLSWave::file_offset); if (w != this->waves.end()) { cue->ulOffset = (ULONG)(w - this->waves.begin()); } else { diff --git a/src/music_gui.cpp b/src/music_gui.cpp index bcad0b15f0..d5da2502fc 100644 --- a/src/music_gui.cpp +++ b/src/music_gui.cpp @@ -188,7 +188,7 @@ void MusicSystem::ChangeMusicSet(const std::string &set_name) */ void MusicSystem::SetPositionBySetIndex(uint set_index) { - auto it = std::find_if(std::begin(this->active_playlist), std::end(this->active_playlist), [&set_index](const PlaylistEntry &ple) { return ple.set_index == set_index; }); + auto it = std::ranges::find(this->active_playlist, set_index, &PlaylistEntry::set_index); if (it != std::end(this->active_playlist)) this->playlist_position = std::distance(std::begin(this->active_playlist), it); } diff --git a/src/newgrf_class_func.h b/src/newgrf_class_func.h index fa2de3fecb..57c2dda438 100644 --- a/src/newgrf_class_func.h +++ b/src/newgrf_class_func.h @@ -31,7 +31,7 @@ void NewGRFClass::Reset() template Tindex NewGRFClass::Allocate(uint32_t global_id) { - auto found = std::find_if(std::begin(NewGRFClass::classes), std::end(NewGRFClass::classes), [global_id](const auto &cls) { return cls.global_id == global_id; }); + auto found = std::ranges::find(NewGRFClass::classes, global_id, &NewGRFClass::global_id); /* Id is already allocated, so reuse it. */ if (found != std::end(NewGRFClass::classes)) return found->Index(); diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 95d10d6308..1ce4e1304e 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -36,7 +36,7 @@ TemporaryStorageArray _temp_store; if (group == nullptr) return nullptr; const GRFFile *grf = object.grffile; - auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](const NewGRFProfiler &pr) { return pr.grffile == grf; }); + auto profiler = std::ranges::find(_newgrf_profilers, grf, &NewGRFProfiler::grffile); if (profiler == _newgrf_profilers.end() || !profiler->active) { if (top_level) _temp_store.ClearChanges(); diff --git a/src/newgrf_townname.cpp b/src/newgrf_townname.cpp index ae95d79525..bf39385af5 100644 --- a/src/newgrf_townname.cpp +++ b/src/newgrf_townname.cpp @@ -27,7 +27,7 @@ static std::vector _grf_townname_names; GRFTownName *GetGRFTownName(uint32_t grfid) { - auto found = std::find_if(std::begin(_grf_townnames), std::end(_grf_townnames), [&grfid](const GRFTownName &t) { return t.grfid == grfid; }); + auto found = std::ranges::find(_grf_townnames, grfid, &GRFTownName::grfid); if (found != std::end(_grf_townnames)) return &*found; return nullptr; } @@ -44,7 +44,7 @@ GRFTownName *AddGRFTownName(uint32_t grfid) void DelGRFTownName(uint32_t grfid) { - _grf_townnames.erase(std::find_if(std::begin(_grf_townnames), std::end(_grf_townnames), [&grfid](const GRFTownName &t) { return t.grfid == grfid; })); + _grf_townnames.erase(std::ranges::find(_grf_townnames, grfid, &GRFTownName::grfid)); } static void RandomPart(StringBuilder &builder, const GRFTownName *t, uint32_t seed, uint8_t id) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 1a8361ff3f..9ae95b51a9 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2935,7 +2935,7 @@ SaveOrLoadResult SaveWithFilter(std::shared_ptr writer, bool threade */ static const SaveLoadFormat *DetermineSaveLoadFormat(uint32_t tag, uint32_t raw_version) { - auto fmt = std::find_if(std::begin(_saveload_formats), std::end(_saveload_formats), [tag](const auto &fmt) { return fmt.tag == tag; }); + auto fmt = std::ranges::find(_saveload_formats, tag, &SaveLoadFormat::tag); if (fmt != std::end(_saveload_formats)) { /* Check version number */ _sl_version = (SaveLoadVersion)(TO_BE32(raw_version) >> 16); @@ -2958,7 +2958,7 @@ static const SaveLoadFormat *DetermineSaveLoadFormat(uint32_t tag, uint32_t raw_ _sl_minor_version = 0; /* Try to find the LZO savegame format; it uses 'OTTD' as tag. */ - fmt = std::find_if(std::begin(_saveload_formats), std::end(_saveload_formats), [](const auto &fmt) { return fmt.tag == SAVEGAME_TAG_LZO; }); + fmt = std::ranges::find(_saveload_formats, SAVEGAME_TAG_LZO, &SaveLoadFormat::tag); if (fmt == std::end(_saveload_formats)) { /* Who removed the LZO savegame format definition? When built without LZO support, * the formats must still list it just without a method to read the file. diff --git a/src/station.cpp b/src/station.cpp index 0bf1926ef6..91438777ce 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -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); } diff --git a/src/texteff.cpp b/src/texteff.cpp index fbec86d04f..a5092e624d 100644 --- a/src/texteff.cpp +++ b/src/texteff.cpp @@ -42,7 +42,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8_t duration, Te { if (_game_mode == GM_MENU) return INVALID_TE_ID; - auto it = std::find_if(std::begin(_text_effects), std::end(_text_effects), [](const TextEffect &te) { return te.string_id == INVALID_STRING_ID; }); + auto it = std::ranges::find(_text_effects, INVALID_STRING_ID, &TextEffect::string_id); if (it == std::end(_text_effects)) { /* _text_effects.size() is the maximum ID + 1 that has been allocated. We should not allocate INVALID_TE_ID or beyond. */ if (_text_effects.size() >= INVALID_TE_ID) return INVALID_TE_ID; diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index eec8220940..2251b095b9 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -403,7 +403,7 @@ void TextfileWindow::NavigateHistory(int delta) switch (ClassifyHyperlink(link.destination, this->trusted)) { case HyperlinkType::Internal: { - auto it = std::find_if(this->link_anchors.cbegin(), this->link_anchors.cend(), [&](const Hyperlink &other) { return link.destination == other.destination; }); + auto it = std::ranges::find(this->link_anchors, link.destination, &Hyperlink::destination); if (it != this->link_anchors.cend()) { this->AppendHistory(this->filepath); this->ScrollToLine(it->line); @@ -484,7 +484,7 @@ void TextfileWindow::NavigateToFile(std::string newfile, size_t line) if (anchor.empty() || line != 0) { this->ScrollToLine(line); } else { - auto anchor_dest = std::find_if(this->link_anchors.cbegin(), this->link_anchors.cend(), [&](const Hyperlink &other) { return anchor == other.destination; }); + auto anchor_dest = std::ranges::find(this->link_anchors, anchor, &Hyperlink::destination); if (anchor_dest != this->link_anchors.cend()) { this->ScrollToLine(anchor_dest->line); this->UpdateHistoryScrollpos(); diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index 068fa3cedb..2d010f8d42 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -65,8 +65,6 @@ struct TouchBarButton { SpriteID sprite; MainToolbarHotkeys hotkey; NSString *fallback_text; - - bool operator ==(const NSTouchBarItemIdentifier other) const { return this->key == other; } }; /* 9 items can be displayed on the touch bar when using default buttons. */ @@ -493,7 +491,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel - (void)touchBarButtonAction:(id)sender { NSButton *btn = (NSButton *)sender; - if (auto item = std::find(_touchbar_buttons.cbegin(), _touchbar_buttons.cend(), (NSTouchBarItemIdentifier)btn.identifier); item != _touchbar_buttons.cend()) { + if (auto item = std::ranges::find(_touchbar_buttons, (NSTouchBarItemIdentifier)btn.identifier, &TouchBarButton::key); item != _touchbar_buttons.end()) { HandleToolbarHotkey(item->hotkey); } } @@ -519,8 +517,8 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel - (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { - auto item = std::find(_touchbar_buttons.cbegin(), _touchbar_buttons.cend(), identifier); - assert(item != _touchbar_buttons.cend()); + auto item = std::ranges::find(_touchbar_buttons, identifier, &TouchBarButton::key); + assert(item != _touchbar_buttons.end()); NSButton *button = [ NSButton buttonWithTitle:item->fallback_text target:self action:@selector(touchBarButtonAction:) ]; button.identifier = identifier; @@ -540,8 +538,8 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel /* Re-create button images from OTTD sprites. */ for (NSTouchBarItemIdentifier ident in self.touchBar.itemIdentifiers) { - auto item = std::find(_touchbar_buttons.cbegin(), _touchbar_buttons.cend(), ident); - if (item == _touchbar_buttons.cend()) continue; + auto item = std::ranges::find(_touchbar_buttons, ident, &TouchBarButton::key); + if (item == _touchbar_buttons.end()) continue; NSCustomTouchBarItem *tb_item = [ self.touchBar itemForIdentifier:ident ]; NSButton *button = tb_item.view; @@ -830,7 +828,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel BOOL interpret_keys = YES; if (down) { /* Map keycode to OTTD code. */ - auto vk = std::find_if(std::begin(_vk_mapping), std::end(_vk_mapping), [=](const CocoaVkMapping &m) { return m.vk_from == keycode; }); + auto vk = std::ranges::find(_vk_mapping, keycode, &CocoaVkMapping::vk_from); uint32_t pressed_key = vk != std::end(_vk_mapping) ? vk->map_to : 0; if (modifiers & NSEventModifierFlagShift) pressed_key |= WKC_SHIFT;