Merge pull request #13117 from mitaclaw/ranges-modernization-9-trivial-find

Ranges Algorithms Modernization - Find
This commit is contained in:
Tilka
2024-10-11 20:27:18 +01:00
committed by GitHub
32 changed files with 71 additions and 84 deletions

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

@ -170,10 +170,9 @@ bool ResourcePack::Install(const std::string& path)
continue;
const std::string texture_name = texture_zip_path.substr(texture_zip_path_prefix.size());
auto texture_it = std::find_if(
m_textures.cbegin(), m_textures.cend(), [&texture_name](const std::string& texture) {
return mz_path_compare_wc(texture.c_str(), texture_name.c_str(), 1) == MZ_OK;
});
auto texture_it = std::ranges::find_if(m_textures, [&texture_name](const std::string& texture) {
return mz_path_compare_wc(texture.c_str(), texture_name.c_str(), 1) == MZ_OK;
});
if (texture_it == m_textures.cend())
continue;
const auto texture = *texture_it;