From 9190443d951c21ab24201d033accf90b4d172f46 Mon Sep 17 00:00:00 2001 From: Kamikadze <40305144+Kam1k4dze@users.noreply.github.com> Date: Fri, 30 May 2025 18:25:59 +0500 Subject: refactor: use std::ranges whenever possible (#10584) --- src/helpers/MiscFunctions.cpp | 8 ++++---- src/helpers/Monitor.cpp | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'src/helpers') diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index ed67618e..ddd16144 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -243,7 +243,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { namedWSes.push_back(ws->m_id); } - std::sort(namedWSes.begin(), namedWSes.end()); + std::ranges::sort(namedWSes); if (absolute) { // 1-index @@ -388,7 +388,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) { validWSes.push_back(ws->m_id); } - std::sort(validWSes.begin(), validWSes.end()); + std::ranges::sort(validWSes); ssize_t currentItem = -1; @@ -623,7 +623,7 @@ std::expected configStringToInt(const std::string& VALUE) const auto VALUEWITHOUTFUNC = trim(VALUE.substr(5, VALUE.length() - 6)); // try doing it the comma way first - if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 3) { + if (std::ranges::count(VALUEWITHOUTFUNC, ',') == 3) { // cool std::string rolling = VALUEWITHOUTFUNC; auto r = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); @@ -657,7 +657,7 @@ std::expected configStringToInt(const std::string& VALUE) const auto VALUEWITHOUTFUNC = trim(VALUE.substr(4, VALUE.length() - 5)); // try doing it the comma way first - if (std::count(VALUEWITHOUTFUNC.begin(), VALUEWITHOUTFUNC.end(), ',') == 2) { + if (std::ranges::count(VALUEWITHOUTFUNC, ',') == 2) { // cool std::string rolling = VALUEWITHOUTFUNC; auto r = configStringToInt(trim(rolling.substr(0, rolling.find(',')))); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index d7536a39..5afd0123 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include using namespace Hyprutils::String; using namespace Hyprutils::Utils; @@ -189,7 +191,7 @@ void CMonitor::onConnect(bool noRule) { RASSERT(thisWrapper->get(), "CMonitor::onConnect: Had no wrapper???"); - if (std::find_if(g_pCompositor->m_monitors.begin(), g_pCompositor->m_monitors.end(), [&](auto& other) { return other.get() == this; }) == g_pCompositor->m_monitors.end()) + if (std::ranges::find_if(g_pCompositor->m_monitors, [&](auto& other) { return other.get() == this; }) == g_pCompositor->m_monitors.end()) g_pCompositor->m_monitors.push_back(*thisWrapper); m_enabled = true; @@ -320,7 +322,7 @@ void CMonitor::onDisconnect(bool destroy) { // remove mirror if (m_mirrorOf) { - m_mirrorOf->m_mirrors.erase(std::find_if(m_mirrorOf->m_mirrors.begin(), m_mirrorOf->m_mirrors.end(), [&](const auto& other) { return other == m_self; })); + m_mirrorOf->m_mirrors.erase(std::ranges::find_if(m_mirrorOf->m_mirrors, [&](const auto& other) { return other == m_self; })); // unlock software for mirrored monitor g_pPointerManager->unlockSoftwareForMonitor(m_mirrorOf.lock()); @@ -486,7 +488,7 @@ bool CMonitor::applyMonitorRule(SMonitorRule* pMonitorRule, bool force) { std::ranges::sort(sortedModes, sortFunc); if (sortedModes.size() > 3) sortedModes.erase(sortedModes.begin() + 3, sortedModes.end()); - requestedModes.insert(requestedModes.end(), sortedModes.rbegin(), sortedModes.rend()); + requestedModes.insert_range(requestedModes.end(), sortedModes | std::views::reverse); }; // last fallback is always preferred mode @@ -1019,7 +1021,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) { // disable mirroring if (m_mirrorOf) { - m_mirrorOf->m_mirrors.erase(std::find_if(m_mirrorOf->m_mirrors.begin(), m_mirrorOf->m_mirrors.end(), [&](const auto& other) { return other == m_self; })); + m_mirrorOf->m_mirrors.erase(std::ranges::find_if(m_mirrorOf->m_mirrors, [&](const auto& other) { return other == m_self; })); // unlock software for mirrored monitor g_pPointerManager->unlockSoftwareForMonitor(m_mirrorOf.lock()); @@ -1046,7 +1048,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) { RASSERT(thisWrapper->get(), "CMonitor::setMirror: Had no wrapper???"); - if (std::find_if(g_pCompositor->m_monitors.begin(), g_pCompositor->m_monitors.end(), [&](auto& other) { return other.get() == this; }) == g_pCompositor->m_monitors.end()) { + if (std::ranges::find_if(g_pCompositor->m_monitors, [&](auto& other) { return other.get() == this; }) == g_pCompositor->m_monitors.end()) { g_pCompositor->m_monitors.push_back(*thisWrapper); } -- cgit v1.2.3