Modernize `std::find` with ranges

This commit is contained in:
mitaclaw 2024-09-20 22:18:04 -07:00
parent b5f7a50874
commit 6ca7e2856b
7 changed files with 10 additions and 10 deletions

View File

@ -85,7 +85,7 @@ bool IniFile::Section::Delete(std::string_view key)
return false;
values.erase(it);
keys_order.erase(std::find(keys_order.begin(), keys_order.end(), key));
keys_order.erase(std::ranges::find(keys_order, key));
return true;
}

View File

@ -59,7 +59,7 @@ static std::optional<DiscIO::Language> TryParseLanguage(const std::string& local
"ja", "en", "de", "fr", "es", "it", "nl", "zh", "zh", "ko",
};
const auto it = std::find(LANGUAGES.cbegin(), LANGUAGES.cend(), split_locale[0]);
const auto it = std::ranges::find(LANGUAGES, split_locale[0]);
if (it == LANGUAGES.cend())
return std::nullopt;
@ -142,7 +142,7 @@ static std::optional<u8> ComputeDefaultCountry()
if (country == "BQ" || country == "CW" || country == "SX")
country = "AN";
const auto it = std::find(COUNTRIES.cbegin(), COUNTRIES.cend(), country);
const auto it = std::ranges::find(COUNTRIES, country);
if (it == COUNTRIES.cend())
return std::nullopt;

View File

@ -252,7 +252,7 @@ HitType CodeTrace::TraceLogic(const TraceOutput& current_instr, bool first_hit)
return HitType::SKIP;
// The reg_itr will be used later for erasing.
auto reg_itr = std::find(m_reg_autotrack.begin(), m_reg_autotrack.end(), instr.reg0);
auto reg_itr = std::ranges::find(m_reg_autotrack, instr.reg0);
const bool match_reg123 =
(!instr.reg1.empty() && std::find(m_reg_autotrack.begin(), m_reg_autotrack.end(),
instr.reg1) != m_reg_autotrack.end()) ||

View File

@ -77,7 +77,7 @@ std::optional<PatchEntry> DeserializeLine(std::string line)
entry.conditional = true;
}
const auto iter = std::find(s_patch_type_strings.begin(), s_patch_type_strings.end(), items[1]);
const auto iter = std::ranges::find(s_patch_type_strings, items[1]);
if (iter == s_patch_type_strings.end())
return std::nullopt;
entry.type = static_cast<PatchType>(std::distance(s_patch_type_strings.begin(), iter));

View File

@ -396,7 +396,7 @@ void GeckoCodeWidget::DownloadCodes()
for (const auto& code : codes)
{
auto it = std::find(m_gecko_codes.begin(), m_gecko_codes.end(), code);
auto it = std::ranges::find(m_gecko_codes, code);
if (it == m_gecko_codes.end())
{

View File

@ -85,7 +85,7 @@ std::vector<ResourcePack>& GetPacks()
std::vector<ResourcePack*> GetLowerPriorityPacks(const ResourcePack& pack)
{
std::vector<ResourcePack*> list;
for (auto it = std::find(packs.begin(), packs.end(), pack) + 1; it != packs.end(); ++it)
for (auto it = std::ranges::find(packs, pack) + 1; it != packs.end(); ++it)
{
auto& entry = *it;
if (!IsInstalled(pack))
@ -100,7 +100,7 @@ std::vector<ResourcePack*> GetLowerPriorityPacks(const ResourcePack& pack)
std::vector<ResourcePack*> GetHigherPriorityPacks(const ResourcePack& pack)
{
std::vector<ResourcePack*> list;
auto end = std::find(packs.begin(), packs.end(), pack);
auto end = std::ranges::find(packs, pack);
for (auto it = packs.begin(); it != end; ++it)
{
@ -145,7 +145,7 @@ bool Remove(ResourcePack& pack)
if (!result)
return false;
auto pack_iterator = std::find(packs.begin(), packs.end(), pack);
auto pack_iterator = std::ranges::find(packs, pack);
if (pack_iterator == packs.end())
return false;

View File

@ -2814,7 +2814,7 @@ TextureCacheBase::InvalidateTexture(TexAddrCache::iterator iter, bool discard_pe
// Xenoblade's sunset scene, where 35 copies are done per frame, and 25 of them are
// copied to the same address, and can be skipped.
ReleaseEFBCopyStagingTexture(std::move(entry->pending_efb_copy));
auto pending_it = std::find(m_pending_efb_copies.begin(), m_pending_efb_copies.end(), entry);
auto pending_it = std::ranges::find(m_pending_efb_copies, entry);
if (pending_it != m_pending_efb_copies.end())
m_pending_efb_copies.erase(pending_it);
}