Skip to content

Commit

Permalink
Modernize std::none_of with ranges
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mitaclaw committed Dec 16, 2024
1 parent 140252f commit 2b0cd16
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 27 deletions.
7 changes: 3 additions & 4 deletions Source/Android/jni/Cheats/GraphicsModGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/NandPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 6 additions & 11 deletions Source/Core/Core/PowerPC/Jit64/RegCache/JitRegCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions Source/Core/DolphinQt/Config/GraphicsModListWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/DolphinQt/ConvertDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/BoundingBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 2b0cd16

Please sign in to comment.