Modernize `std::count_if` with ranges

This commit is contained in:
mitaclaw 2024-09-21 18:24:22 -07:00
parent c46060e298
commit 4cc5e1972a
3 changed files with 7 additions and 10 deletions

View File

@ -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

View File

@ -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<u32>(
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<u32>(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<std::array<u8, 20>> ESCore::GetSharedContents() const

View File

@ -176,9 +176,8 @@ Joystick::Joystick(const LPDIRECTINPUTDEVICE8 device) : m_device(device)
std::list<DIDEVICEOBJECTINSTANCE> 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);
}