From 4cc5e1972ae5643af001276758c4456ee7292f41 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sat, 21 Sep 2024 18:24:22 -0700 Subject: [PATCH] Modernize `std::count_if` with ranges --- Source/Core/Common/StringUtil.cpp | 3 +-- Source/Core/Core/IOS/ES/NandUtils.cpp | 9 ++++----- .../ControllerInterface/DInput/DInputJoystick.cpp | 5 ++--- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 508ba8baf8..9881708a27 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -403,8 +403,7 @@ void StringPopBackIf(std::string* s, char c) size_t StringUTF8CodePointCount(std::string_view str) { - return str.size() - - std::count_if(str.begin(), str.end(), [](char c) -> bool { return (c & 0xC0) == 0x80; }); + return str.size() - std::ranges::count_if(str, [](char c) -> bool { return (c & 0xC0) == 0x80; }); } #ifdef _WIN32 diff --git a/Source/Core/Core/IOS/ES/NandUtils.cpp b/Source/Core/Core/IOS/ES/NandUtils.cpp index 7198049462..9c742974b8 100644 --- a/Source/Core/Core/IOS/ES/NandUtils.cpp +++ b/Source/Core/Core/IOS/ES/NandUtils.cpp @@ -219,11 +219,10 @@ ESCore::GetStoredContentsFromTMD(const ES::TMDReader& tmd, u32 ESCore::GetSharedContentsCount() const { const auto entries = m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1"); - return static_cast( - std::count_if(entries->begin(), entries->end(), [this](const std::string& entry) { - return !m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1/" + entry) && - entry.size() == 12 && entry.compare(8, 4, ".app") == 0; - })); + return static_cast(std::ranges::count_if(*entries, [this](const std::string& entry) { + return !m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1/" + entry) && + entry.size() == 12 && entry.compare(8, 4, ".app") == 0; + })); } std::vector> ESCore::GetSharedContents() const diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp index 577bd761d4..5d3e353a0a 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp @@ -176,9 +176,8 @@ Joystick::Joystick(const LPDIRECTINPUTDEVICE8 device) : m_device(device) std::list objects; if (SUCCEEDED(m_device->EnumObjects(DIEnumDeviceObjectsCallback, (LPVOID)&objects, DIDFT_AXIS))) { - const int num_ff_axes = - std::count_if(std::begin(objects), std::end(objects), - [](const auto& pdidoi) { return (pdidoi.dwFlags & DIDOI_FFACTUATOR) != 0; }); + const int num_ff_axes = std::ranges::count_if( + objects, [](const auto& pdidoi) { return (pdidoi.dwFlags & DIDOI_FFACTUATOR) != 0; }); InitForceFeedback(m_device, num_ff_axes); }