Modernize std::count with ranges

This commit is contained in:
mitaclaw 2024-09-21 18:13:21 -07:00
parent ed5eb49d47
commit c46060e298
3 changed files with 3 additions and 3 deletions

View File

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

View File

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

View File

@ -121,7 +121,7 @@ TEST_F(FileSystemTest, CreateFile)
const Result<std::vector<std::string>> 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