From a159c36a1083b14b6ec066d824d6528cabbf197b Mon Sep 17 00:00:00 2001 From: statementreply Date: Fri, 29 Jan 2021 00:05:13 +0800 Subject: [PATCH 1/3] feature/spaceship: Clause 29: Input/output --- stl/inc/filesystem | 26 ++++++++++++ tests/std/tests/P1614R2_spaceship/test.cpp | 49 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 0f9bec6e02..39fff532e9 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -26,6 +26,10 @@ #include #include +#if _HAS_CXX20 +#include +#endif // _HAS_CXX20 + #pragma pack(push, _CRT_PACKING) #pragma warning(push, _STL_WARNING_LEVEL) #pragma warning(disable : _STL_DISABLED_WARNINGS) @@ -1399,6 +1403,11 @@ namespace filesystem { return _Left.compare(_Right) == 0; } +#if _HAS_CXX20 + _NODISCARD friend strong_ordering operator<=>(const path& _Left, const path& _Right) noexcept { + return _Left.compare(_Right) <=> 0; + } +#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv _NODISCARD friend bool operator!=(const path& _Left, const path& _Right) noexcept { return _Left.compare(_Right) != 0; } @@ -1418,6 +1427,7 @@ namespace filesystem { _NODISCARD friend bool operator>=(const path& _Left, const path& _Right) noexcept { return _Left.compare(_Right) >= 0; } +#endif // !_HAS_CXX20 _NODISCARD friend path operator/(const path& _Left, const path& _Right) { // append a pair of paths together return path(_Left) /= _Right; @@ -1967,6 +1977,12 @@ namespace filesystem { return _Myperms; } +#if _HAS_CXX20 + _NODISCARD friend bool operator==(const file_status& _Lhs, const file_status& _Rhs) noexcept { + return _Lhs._Myftype == _Rhs._Myftype && _Lhs._Myperms == _Rhs._Myperms; + } +#endif // _HAS_CXX20 + void _Refresh(const __std_win_error _Error, const __std_fs_stats& _Stats) noexcept { if (_Error == __std_win_error::_Success) { const auto _Attrs = _Stats._Attributes; @@ -2453,6 +2469,11 @@ namespace filesystem { return _Path == _Rhs._Path; } +#if _HAS_CXX20 + _NODISCARD strong_ordering operator<=>(const directory_entry& _Rhs) const noexcept { + return _Path <=> _Rhs._Path; + } +#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv _NODISCARD bool operator!=(const directory_entry& _Rhs) const noexcept { return _Path != _Rhs._Path; } @@ -2468,6 +2489,7 @@ namespace filesystem { _NODISCARD bool operator>=(const directory_entry& _Rhs) const noexcept { return _Path >= _Rhs._Path; } +#endif // !_HAS_CXX20 private: void _Refresh(const __std_fs_find_data& _Data) noexcept { @@ -3641,6 +3663,10 @@ namespace filesystem { uintmax_t capacity; uintmax_t free; uintmax_t available; + +#if _HAS_CXX20 + _NODISCARD friend constexpr bool operator==(const space_info&, const space_info&) noexcept = default; +#endif // _HAS_CXX20 }; _NODISCARD inline space_info space(const path& _Target) { diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index 734bf99f7d..c488238b56 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -482,6 +483,54 @@ void ordering_test_cases() { spaceship_test(c_mem[0], c_mem[0], c_mem[1]); } + { // filesystem::space_info + constexpr std::filesystem::space_info si1{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; + constexpr std::filesystem::space_info si2{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; + constexpr std::filesystem::space_info si3{4'000'000'000'000, 2'000'000'000'000, 2'000'000'000'000}; + constexpr std::filesystem::space_info si4{4'000'000'000'000, 3'000'000'000'000, 1'000'000'000'000}; + constexpr std::filesystem::space_info si5{3'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000}; + + static_assert(si1 == si2); + static_assert(si1 != si3); + static_assert(si1 != si4); + static_assert(si1 != si5); + + assert(si1 == si2); + assert(si1 != si3); + assert(si1 != si4); + assert(si1 != si5); + } + { // filesystem::path + const std::filesystem::path p1{R"(a/b/c)"}; + const std::filesystem::path p2{LR"(a\b\c)"}; + const std::filesystem::path p3{R"(a/b/d)"}; + + spaceship_test(p1, p2, p3); + } + { // filesystem::file_status + std::filesystem::file_status s1; + s1.type(std::filesystem::file_type::regular); + s1.permissions(std::filesystem::perms{0755}); + + std::filesystem::file_status s2 = s1; + + std::filesystem::file_status s3 = s1; + s3.type(std::filesystem::file_type::directory); + + std::filesystem::file_status s4 = s1; + s4.permissions(std::filesystem::perms{0600}); + + assert(s1 == s2); + assert(s1 != s3); + assert(s1 != s4); + } + { // filesystem::directory_entry + const std::filesystem::directory_entry de1{u8R"(a/b/c)"}; + const std::filesystem::directory_entry de2{uR"(a\b\c)"}; + const std::filesystem::directory_entry de3{u8R"(a/b/d)"}; + + spaceship_test(de1, de2, de3); + } { // thread::id std::thread::id id1; std::thread::id id1_equal; From 4c410858c90affb3679ba597fe1523976ea429a1 Mon Sep 17 00:00:00 2001 From: statementreply Date: Fri, 29 Jan 2021 00:08:31 +0800 Subject: [PATCH 2/3] feature/spaceship: Clause 28: Localization --- stl/inc/xlocale | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stl/inc/xlocale b/stl/inc/xlocale index fcdbf63bb1..5fe52ccd94 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -389,9 +389,11 @@ public: return _Ptr == _Loc._Ptr || (name().compare("*") != 0 && name().compare(_Loc.name()) == 0); } +#if !_HAS_CXX20 _NODISCARD bool operator!=(const locale& _Right) const { return !(*this == _Right); } +#endif // !_HAS_CXX20 static _MRTIMP2_PURE const locale& __CLRCALL_PURE_OR_CDECL classic(); // classic "C" locale From a3eec75177739543d4e357d1523f4932015b41b5 Mon Sep 17 00:00:00 2001 From: statementreply Date: Fri, 29 Jan 2021 21:33:20 +0800 Subject: [PATCH 3/3] Remove directory_entry::operator< in C++20 mode --- stl/inc/filesystem | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 39fff532e9..ef4141d2f8 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -2461,10 +2461,6 @@ namespace filesystem { return _Result._Status; } - _NODISCARD bool operator<(const directory_entry& _Rhs) const noexcept { - return _Path < _Rhs._Path; - } - _NODISCARD bool operator==(const directory_entry& _Rhs) const noexcept { return _Path == _Rhs._Path; } @@ -2478,6 +2474,10 @@ namespace filesystem { return _Path != _Rhs._Path; } + _NODISCARD bool operator<(const directory_entry& _Rhs) const noexcept { + return _Path < _Rhs._Path; + } + _NODISCARD bool operator<=(const directory_entry& _Rhs) const noexcept { return _Path <= _Rhs._Path; }