diff --git a/libcxx/docs/ReleaseNotes.rst b/libcxx/docs/ReleaseNotes.rst --- a/libcxx/docs/ReleaseNotes.rst +++ b/libcxx/docs/ReleaseNotes.rst @@ -41,6 +41,8 @@ Improvements and New Features ----------------------------- +* Implemented ``operator<=>`` for ``std::filesystem::directory_entry`` + Deprecations and Removals ------------------------- diff --git a/libcxx/include/__filesystem/directory_entry.h b/libcxx/include/__filesystem/directory_entry.h --- a/libcxx/include/__filesystem/directory_entry.h +++ b/libcxx/include/__filesystem/directory_entry.h @@ -215,21 +215,25 @@ return __get_symlink_status(&__ec); } - _LIBCPP_INLINE_VISIBILITY - bool operator<(directory_entry const& __rhs) const noexcept { - return __p_ < __rhs.__p_; - } _LIBCPP_INLINE_VISIBILITY bool operator==(directory_entry const& __rhs) const noexcept { return __p_ == __rhs.__p_; } +#if TEST_STD_VER <= 17 + _LIBCPP_INLINE_VISIBILITY bool operator!=(directory_entry const& __rhs) const noexcept { return __p_ != __rhs.__p_; } + _LIBCPP_INLINE_VISIBILITY + bool operator<(directory_entry const& __rhs) const noexcept { + return __p_ < __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY bool operator<=(directory_entry const& __rhs) const noexcept { return __p_ <= __rhs.__p_; @@ -245,6 +249,15 @@ return __p_ >= __rhs.__p_; } +#else // TEST_STD_VER <= 17 + + _LIBCPP_INLINE_VISIBILITY + strong_ordering operator<=>(const directory_entry& __rhs) const noexcept { + return __p_ <=> __rhs.__p_; + } + +#endif // TEST_STD_VER <= 17 + template _LIBCPP_INLINE_VISIBILITY friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) { diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/comparisons.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/comparisons.pass.cpp --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/comparisons.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/comparisons.pass.cpp @@ -44,6 +44,9 @@ CHECK_OP(<=); CHECK_OP(> ); CHECK_OP(>=); +#if TEST_STD_VER > 17 + CHECK_OP(>=); +#endif } } #undef CHECK_OP @@ -68,6 +71,9 @@ assert((LHS <= RHS) == (LHSE <= RHSE)); assert((LHS > RHS) == (LHSE > RHSE)); assert((LHS >= RHS) == (LHSE >= RHSE)); +#if TEST_STD_VER > 17 + assert((LHS <=> RHS) == (LHSE <=> RHSE)); +#endif }; for (auto const& TC : TestCases) { const directory_entry L(TC.first);