Skip to content

Commit e68b14a

Browse files
feature/spaceship: Clause 28: Localization, Clause 29: Input/output (#1593)
1 parent b9ef974 commit e68b14a

File tree

3 files changed

+81
-4
lines changed

3 files changed

+81
-4
lines changed

stl/inc/filesystem

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include <xfilesystem_abi.h>
2727
#include <xstring>
2828

29+
#if _HAS_CXX20
30+
#include <compare>
31+
#endif // _HAS_CXX20
32+
2933
#pragma pack(push, _CRT_PACKING)
3034
#pragma warning(push, _STL_WARNING_LEVEL)
3135
#pragma warning(disable : _STL_DISABLED_WARNINGS)
@@ -1399,6 +1403,11 @@ namespace filesystem {
13991403
return _Left.compare(_Right) == 0;
14001404
}
14011405

1406+
#if _HAS_CXX20
1407+
_NODISCARD friend strong_ordering operator<=>(const path& _Left, const path& _Right) noexcept {
1408+
return _Left.compare(_Right) <=> 0;
1409+
}
1410+
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
14021411
_NODISCARD friend bool operator!=(const path& _Left, const path& _Right) noexcept {
14031412
return _Left.compare(_Right) != 0;
14041413
}
@@ -1418,6 +1427,7 @@ namespace filesystem {
14181427
_NODISCARD friend bool operator>=(const path& _Left, const path& _Right) noexcept {
14191428
return _Left.compare(_Right) >= 0;
14201429
}
1430+
#endif // !_HAS_CXX20
14211431

14221432
_NODISCARD friend path operator/(const path& _Left, const path& _Right) { // append a pair of paths together
14231433
return path(_Left) /= _Right;
@@ -1967,6 +1977,12 @@ namespace filesystem {
19671977
return _Myperms;
19681978
}
19691979

1980+
#if _HAS_CXX20
1981+
_NODISCARD friend bool operator==(const file_status& _Lhs, const file_status& _Rhs) noexcept {
1982+
return _Lhs._Myftype == _Rhs._Myftype && _Lhs._Myperms == _Rhs._Myperms;
1983+
}
1984+
#endif // _HAS_CXX20
1985+
19701986
void _Refresh(const __std_win_error _Error, const __std_fs_stats& _Stats) noexcept {
19711987
if (_Error == __std_win_error::_Success) {
19721988
const auto _Attrs = _Stats._Attributes;
@@ -2445,18 +2461,23 @@ namespace filesystem {
24452461
return _Result._Status;
24462462
}
24472463

2448-
_NODISCARD bool operator<(const directory_entry& _Rhs) const noexcept {
2449-
return _Path < _Rhs._Path;
2450-
}
2451-
24522464
_NODISCARD bool operator==(const directory_entry& _Rhs) const noexcept {
24532465
return _Path == _Rhs._Path;
24542466
}
24552467

2468+
#if _HAS_CXX20
2469+
_NODISCARD strong_ordering operator<=>(const directory_entry& _Rhs) const noexcept {
2470+
return _Path <=> _Rhs._Path;
2471+
}
2472+
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv
24562473
_NODISCARD bool operator!=(const directory_entry& _Rhs) const noexcept {
24572474
return _Path != _Rhs._Path;
24582475
}
24592476

2477+
_NODISCARD bool operator<(const directory_entry& _Rhs) const noexcept {
2478+
return _Path < _Rhs._Path;
2479+
}
2480+
24602481
_NODISCARD bool operator<=(const directory_entry& _Rhs) const noexcept {
24612482
return _Path <= _Rhs._Path;
24622483
}
@@ -2468,6 +2489,7 @@ namespace filesystem {
24682489
_NODISCARD bool operator>=(const directory_entry& _Rhs) const noexcept {
24692490
return _Path >= _Rhs._Path;
24702491
}
2492+
#endif // !_HAS_CXX20
24712493

24722494
// [fs.dir.entry.io], inserter
24732495
template <class _Elem, class _Traits>
@@ -3649,6 +3671,10 @@ namespace filesystem {
36493671
uintmax_t capacity;
36503672
uintmax_t free;
36513673
uintmax_t available;
3674+
3675+
#if _HAS_CXX20
3676+
_NODISCARD friend constexpr bool operator==(const space_info&, const space_info&) noexcept = default;
3677+
#endif // _HAS_CXX20
36523678
};
36533679

36543680
_NODISCARD inline space_info space(const path& _Target) {

stl/inc/xlocale

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,11 @@ public:
389389
return _Ptr == _Loc._Ptr || (name().compare("*") != 0 && name().compare(_Loc.name()) == 0);
390390
}
391391

392+
#if !_HAS_CXX20
392393
_NODISCARD bool operator!=(const locale& _Right) const {
393394
return !(*this == _Right);
394395
}
396+
#endif // !_HAS_CXX20
395397

396398
static _MRTIMP2_PURE const locale& __CLRCALL_PURE_OR_CDECL classic(); // classic "C" locale
397399

tests/std/tests/P1614R2_spaceship/test.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <compare>
1010
#include <concepts>
1111
#include <deque>
12+
#include <filesystem>
1213
#include <forward_list>
1314
#include <functional>
1415
#include <iostream>
@@ -482,6 +483,54 @@ void ordering_test_cases() {
482483

483484
spaceship_test<std::strong_ordering>(c_mem[0], c_mem[0], c_mem[1]);
484485
}
486+
{ // filesystem::space_info
487+
constexpr std::filesystem::space_info si1{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000};
488+
constexpr std::filesystem::space_info si2{4'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000};
489+
constexpr std::filesystem::space_info si3{4'000'000'000'000, 2'000'000'000'000, 2'000'000'000'000};
490+
constexpr std::filesystem::space_info si4{4'000'000'000'000, 3'000'000'000'000, 1'000'000'000'000};
491+
constexpr std::filesystem::space_info si5{3'000'000'000'000, 2'000'000'000'000, 1'000'000'000'000};
492+
493+
static_assert(si1 == si2);
494+
static_assert(si1 != si3);
495+
static_assert(si1 != si4);
496+
static_assert(si1 != si5);
497+
498+
assert(si1 == si2);
499+
assert(si1 != si3);
500+
assert(si1 != si4);
501+
assert(si1 != si5);
502+
}
503+
{ // filesystem::path
504+
const std::filesystem::path p1{R"(a/b/c)"};
505+
const std::filesystem::path p2{LR"(a\b\c)"};
506+
const std::filesystem::path p3{R"(a/b/d)"};
507+
508+
spaceship_test<std::strong_ordering>(p1, p2, p3);
509+
}
510+
{ // filesystem::file_status
511+
std::filesystem::file_status s1;
512+
s1.type(std::filesystem::file_type::regular);
513+
s1.permissions(std::filesystem::perms{0755});
514+
515+
std::filesystem::file_status s2 = s1;
516+
517+
std::filesystem::file_status s3 = s1;
518+
s3.type(std::filesystem::file_type::directory);
519+
520+
std::filesystem::file_status s4 = s1;
521+
s4.permissions(std::filesystem::perms{0600});
522+
523+
assert(s1 == s2);
524+
assert(s1 != s3);
525+
assert(s1 != s4);
526+
}
527+
{ // filesystem::directory_entry
528+
const std::filesystem::directory_entry de1{u8R"(a/b/c)"};
529+
const std::filesystem::directory_entry de2{uR"(a\b\c)"};
530+
const std::filesystem::directory_entry de3{u8R"(a/b/d)"};
531+
532+
spaceship_test<std::strong_ordering>(de1, de2, de3);
533+
}
485534
{ // thread::id
486535
std::thread::id id1;
487536
std::thread::id id1_equal;

0 commit comments

Comments
 (0)