From e68b14a2724f096ab4e3c7857fee5960ae853930 Mon Sep 17 00:00:00 2001 From: statementreply Date: Wed, 3 Feb 2021 15:57:54 +0800 Subject: [PATCH] feature/spaceship: Clause 28: Localization, Clause 29: Input/output (#1593) --- stl/inc/filesystem | 34 +++++++++++++-- stl/inc/xlocale | 2 + tests/std/tests/P1614R2_spaceship/test.cpp | 49 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/stl/inc/filesystem b/stl/inc/filesystem index c0444a29bd..075a08b158 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; @@ -2445,18 +2461,23 @@ 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; } +#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; } + _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; } @@ -2468,6 +2489,7 @@ namespace filesystem { _NODISCARD bool operator>=(const directory_entry& _Rhs) const noexcept { return _Path >= _Rhs._Path; } +#endif // !_HAS_CXX20 // [fs.dir.entry.io], inserter template @@ -3649,6 +3671,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/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 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;