From 973abff4b96026533862b47f7d4ad0067825e091 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Thu, 21 Jan 2021 19:01:42 +0100 Subject: [PATCH 1/2] refs #89, added operator==() to fs::file_status --- README.md | 4 +++- include/ghc/filesystem.hpp | 2 +- test/filesystem_test.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59fade2..58a131e 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ It is from after the standardization of C++17 but it contains the latest filesys interface changes compared to the [Working Draft N4659](https://github.com/cplusplus/draft/raw/master/papers/n4659.pdf). Staring with v1.4.0, when compiled using C++20, it adapts to the changes according to path sorting order -and `std::u8string` handling from [Working Draft N4680](https://isocpp.org/files/papers/N4860.pdf). +and `std::u8string` handling from [Working Draft N4860](https://isocpp.org/files/papers/N4860.pdf). I want to thank the people working on improving C++, I really liked how the language evolved with C++11 and the following standards. Keep on the good work! @@ -554,6 +554,8 @@ to the expected behavior. ### v1.4.2 (WIP) +* Enhancement for [#89](https://github.com/gulrak/filesystem/issues/89), `fs::file_status` + now supports `operator==` introduced in `std::filesystem` with C++20. * Refactoring for [#88](https://github.com/gulrak/filesystem/issues/88), `fs::path::parent_path()` had a performance issue, as it was still using a loop based approach to recreate the parent from elements. This created lots of temporaries and was too slow diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 9bf36f4..ec707ed 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -696,7 +696,7 @@ public: // 30.10.11.2 observers file_type type() const noexcept; perms permissions() const noexcept; - + friend bool operator==(const file_status& lhs, const file_status& rhs) noexcept { return lhs.type() == rhs.type() && lhs.permissions() == rhs.permissions(); } private: file_type _type; perms _perms; diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index eb9e879..23e6c01 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -1219,6 +1219,15 @@ TEST_CASE("30.10.11 class file_status", "[filesystem][file_status][fs.class.file CHECK(fs.type() == fs::file_type::regular); CHECK(fs.permissions() == fs::perms::unknown); } + { + fs::file_status fs1{fs::file_type::regular, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec}; + fs::file_status fs2{fs::file_type::regular, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec}; + fs::file_status fs3{fs::file_type::directory, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec}; + fs::file_status fs4{fs::file_type::regular, fs::perms::owner_read | fs::perms::owner_write}; + CHECK(fs1 == fs2); + CHECK_FALSE(fs1 == fs3); + CHECK_FALSE(fs1 == fs4); + } } TEST_CASE("30.10.12 class directory_entry", "[filesystem][directory_entry][fs.dir.entry]") From 05f0aa8ae13dcc2387f465bd10e43d7f590baf23 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Sun, 7 Feb 2021 09:59:06 +0100 Subject: [PATCH 2/2] refs #89, fixing some test code issues --- test/filesystem_test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 23e6c01..2b1a403 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -127,6 +127,14 @@ struct StringMaker static std::string convert(fs::perms const& value) { return std::to_string(static_cast(value)); } }; +template <> +struct StringMaker +{ + static std::string convert(fs::file_status const& value) { + return std::string("[") + std::to_string(static_cast(value.type())) + "," + std::to_string(static_cast(value.permissions())) + "]"; + } +}; + #ifdef __cpp_lib_char8_t template <> struct StringMaker @@ -1219,6 +1227,7 @@ TEST_CASE("30.10.11 class file_status", "[filesystem][file_status][fs.class.file CHECK(fs.type() == fs::file_type::regular); CHECK(fs.permissions() == fs::perms::unknown); } +#if !defined(USE_STD_FS) || defined(GHC_FILESYSTEM_RUNNING_CPP20) { fs::file_status fs1{fs::file_type::regular, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec}; fs::file_status fs2{fs::file_type::regular, fs::perms::owner_read | fs::perms::owner_write | fs::perms::owner_exec}; @@ -1228,6 +1237,7 @@ TEST_CASE("30.10.11 class file_status", "[filesystem][file_status][fs.class.file CHECK_FALSE(fs1 == fs3); CHECK_FALSE(fs1 == fs4); } +#endif } TEST_CASE("30.10.12 class directory_entry", "[filesystem][directory_entry][fs.dir.entry]")