[libcxx-commits] [PATCH] D130860: [libc++] Implement `operator<=>` for `filesystem::directory_entry`

Adrian Vogelsgesang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 31 16:07:40 PDT 2022


avogelsgesang created this revision.
avogelsgesang added reviewers: ldionne, Mordante, philnik.
Herald added a project: All.
avogelsgesang requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Implements part of P1614R2 "The Mothership has Landed"


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130860

Files:
  libcxx/docs/ReleaseNotes.rst
  libcxx/include/__filesystem/directory_entry.h
  libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/comparisons.pass.cpp


Index: libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/comparisons.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/comparisons.pass.cpp
+++ 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);
Index: libcxx/include/__filesystem/directory_entry.h
===================================================================
--- libcxx/include/__filesystem/directory_entry.h
+++ 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 <class _CharT, class _Traits>
   _LIBCPP_INLINE_VISIBILITY
   friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) {
Index: libcxx/docs/ReleaseNotes.rst
===================================================================
--- libcxx/docs/ReleaseNotes.rst
+++ libcxx/docs/ReleaseNotes.rst
@@ -41,6 +41,8 @@
 Improvements and New Features
 -----------------------------
 
+* Implemented ``operator<=>`` for ``std::filesystem::directory_entry``
+
 Deprecations and Removals
 -------------------------
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130860.448894.patch
Type: text/x-patch
Size: 2681 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220731/87aed360/attachment-0001.bin>


More information about the libcxx-commits mailing list