From c46060e2985f24a6668db1061681009997aef896 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Sat, 21 Sep 2024 18:13:21 -0700 Subject: [PATCH] Modernize `std::count` with ranges --- Source/Core/Core/IOS/FS/FileSystemProxy.cpp | 2 +- Source/Core/Core/IOS/FS/HostBackend/FS.cpp | 2 +- Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/IOS/FS/FileSystemProxy.cpp b/Source/Core/Core/IOS/FS/FileSystemProxy.cpp index f69da2f9b5..f2cb61e199 100644 --- a/Source/Core/Core/IOS/FS/FileSystemProxy.cpp +++ b/Source/Core/Core/IOS/FS/FileSystemProxy.cpp @@ -143,7 +143,7 @@ enum class FileLookupMode static SystemTimers::TimeBaseTick EstimateFileLookupTicks(const std::string& path, FileLookupMode mode) { - const size_t number_of_path_components = std::count(path.cbegin(), path.cend(), '/'); + const size_t number_of_path_components = std::ranges::count(path, '/'); if (number_of_path_components == 0) return 0_tbticks; diff --git a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp index da5fa6d983..2d1e1143c9 100644 --- a/Source/Core/Core/IOS/FS/HostBackend/FS.cpp +++ b/Source/Core/Core/IOS/FS/HostBackend/FS.cpp @@ -467,7 +467,7 @@ ResultCode HostFileSystem::CreateFileOrDirectory(Uid uid, Gid gid, const std::st return ResultCode::Invalid; } - if (!is_file && std::count(path.begin(), path.end(), '/') > int(MaxPathDepth)) + if (!is_file && std::ranges::count(path, '/') > int(MaxPathDepth)) return ResultCode::TooManyPathComponents; const auto split_path = SplitPathAndBasename(path); diff --git a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp index b1e6997e34..513f86d4c9 100644 --- a/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp +++ b/Source/UnitTests/Core/IOS/FS/FileSystemTest.cpp @@ -121,7 +121,7 @@ TEST_F(FileSystemTest, CreateFile) const Result> tmp_files = m_fs->ReadDirectory(Uid{0}, Gid{0}, "/tmp"); ASSERT_TRUE(tmp_files.Succeeded()); - EXPECT_EQ(std::count(tmp_files->begin(), tmp_files->end(), "f"), 1u); + EXPECT_EQ(std::ranges::count(*tmp_files, "f"), 1u); // Test invalid paths // Unprintable characters