Modernize `std::none_of` with ranges

In JitRegCache.cpp, the lambda predicate were replaced by a pointer to member function because ranges algorithms are able to invoke those.

In ConvertDialog.cpp, the `std::mem_fn` helper was removed because ranges algorithms are able to handle pointers to member functions as predicates.

In BoundingBox.cpp, the lambda predicate was returning the bool element unchanged, so `std::identity` was a better fit.
This commit is contained in:
mitaclaw 2024-09-30 15:05:17 -07:00
parent 140252ffc0
commit 2b0cd16c8c
7 changed files with 20 additions and 27 deletions

View File

@ -51,10 +51,9 @@ Java_org_dolphinemu_dolphinemu_features_cheats_model_GraphicsModGroup_getMods(JN
for (GraphicsModConfig& mod : mod_group->GetMods())
{
// If no group matches the mod's features, or if the mod has no features, skip it
if (std::none_of(mod.m_features.begin(), mod.m_features.end(),
[&groups](const GraphicsModFeatureConfig& feature) {
return groups.contains(feature.m_group);
}))
if (std::ranges::none_of(mod.m_features, [&groups](const GraphicsModFeatureConfig& feature) {
return groups.contains(feature.m_group);
}))
{
continue;
}

View File

@ -171,6 +171,6 @@ std::string UnescapeFileName(const std::string& filename)
bool IsFileNameSafe(const std::string_view filename)
{
return !filename.empty() && !std::ranges::all_of(filename, [](char c) { return c == '.'; }) &&
std::none_of(filename.begin(), filename.end(), IsIllegalCharacter);
std::ranges::none_of(filename, IsIllegalCharacter);
}
} // namespace Common

View File

@ -369,10 +369,8 @@ RCForkGuard RegCache::Fork()
void RegCache::Discard(BitSet32 pregs)
{
ASSERT_MSG(
DYNA_REC,
std::none_of(m_xregs.begin(), m_xregs.end(), [](const auto& x) { return x.IsLocked(); }),
"Someone forgot to unlock a X64 reg");
ASSERT_MSG(DYNA_REC, std::ranges::none_of(m_xregs, &X64CachedReg::IsLocked),
"Someone forgot to unlock a X64 reg");
for (preg_t i : pregs)
{
@ -393,10 +391,8 @@ void RegCache::Discard(BitSet32 pregs)
void RegCache::Flush(BitSet32 pregs, IgnoreDiscardedRegisters ignore_discarded_registers)
{
ASSERT_MSG(
DYNA_REC,
std::none_of(m_xregs.begin(), m_xregs.end(), [](const auto& x) { return x.IsLocked(); }),
"Someone forgot to unlock a X64 reg");
ASSERT_MSG(DYNA_REC, std::ranges::none_of(m_xregs, &X64CachedReg::IsLocked),
"Someone forgot to unlock a X64 reg");
for (preg_t i : pregs)
{
@ -459,9 +455,8 @@ void RegCache::Commit()
bool RegCache::IsAllUnlocked() const
{
return std::none_of(m_regs.begin(), m_regs.end(), [](const auto& r) { return r.IsLocked(); }) &&
std::none_of(m_xregs.begin(), m_xregs.end(), [](const auto& x) { return x.IsLocked(); }) &&
!IsAnyConstraintActive();
return std::ranges::none_of(m_regs, &PPCCachedReg::IsLocked) &&
std::ranges::none_of(m_xregs, &X64CachedReg::IsLocked) && !IsAnyConstraintActive();
}
void RegCache::PreloadRegisters(BitSet32 to_preload)

View File

@ -138,10 +138,9 @@ void GraphicsModListWidget::RefreshModList()
for (const GraphicsModConfig& mod : m_mod_group.GetMods())
{
// If no group matches the mod's features, or if the mod has no features, skip it
if (std::none_of(mod.m_features.begin(), mod.m_features.end(),
[&groups](const GraphicsModFeatureConfig& feature) {
return groups.contains(feature.m_group);
}))
if (std::ranges::none_of(mod.m_features, [&groups](const GraphicsModFeatureConfig& feature) {
return groups.contains(feature.m_group);
}))
{
continue;
}

View File

@ -248,9 +248,8 @@ void ConvertDialog::OnFormatChanged()
m_compression->setEnabled(m_compression->count() > 1);
// Block scrubbing of RVZ containers and Datel discs
const bool scrubbing_allowed =
format != DiscIO::BlobType::RVZ &&
std::none_of(m_files.begin(), m_files.end(), std::mem_fn(&UICommon::GameFile::IsDatelDisc));
const bool scrubbing_allowed = format != DiscIO::BlobType::RVZ &&
std::ranges::none_of(m_files, &UICommon::GameFile::IsDatelDisc);
m_scrub->setEnabled(scrubbing_allowed);
if (!scrubbing_allowed)

View File

@ -305,9 +305,10 @@ bool HotkeySuppressions::IsSuppressedIgnoringModifiers(Device::Input* input,
return i1 && i2 && (i1 == i2 || i1->IsChild(i2) || i2->IsChild(i1));
};
return std::any_of(it, it_end, [&](auto& s) {
return std::none_of(begin(ignore_modifiers), end(ignore_modifiers),
[&](auto& m) { return is_same_modifier(m->GetInput(), s.first.second); });
return std::any_of(it, it_end, [&](const auto& s) {
return std::ranges::none_of(ignore_modifiers, [&](const auto& m) {
return is_same_modifier(m->GetInput(), s.first.second);
});
});
}

View File

@ -34,7 +34,7 @@ void BoundingBox::Flush()
m_is_valid = false;
if (std::none_of(m_dirty.begin(), m_dirty.end(), [](bool dirty) { return dirty; }))
if (std::ranges::none_of(m_dirty, std::identity{}))
return;
// TODO: Does this make any difference over just writing all the values?