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

Adrian Vogelsgesang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 2 13:04:58 PDT 2022


avogelsgesang updated this revision to Diff 449399.
avogelsgesang added a comment.

Update based on feedback from D130852 <https://reviews.llvm.org/D130852>


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D130859/new/

https://reviews.llvm.org/D130859

Files:
  libcxx/docs/Status/SpaceshipProjects.csv
  libcxx/include/__filesystem/path.h
  libcxx/include/filesystem
  libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp


Index: libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp
===================================================================
--- libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp
+++ libcxx/test/std/input.output/filesystems/class.path/path.member/path.compare.pass.cpp
@@ -22,10 +22,10 @@
 // bool operator<=(path const&, path const&) noexcept;
 // bool operator> (path const&, path const&) noexcept;
 // bool operator>=(path const&, path const&) noexcept;
+// strong_ordering operator<=>(path const&, path const&) noexcept;
 //
 // size_t hash_value(path const&) noexcept;
 
-
 #include "filesystem_include.h"
 #include <type_traits>
 #include <vector>
@@ -118,6 +118,9 @@
       assert((p1 <= p2) == (E <= 0));
       assert((p1 >  p2) == (E >  0));
       assert((p1 >= p2) == (E >= 0));
+#if TEST_STD_VER > 17
+      assert((p1 <=> p2) == (E <=> 0));
+#endif
 
       // Check signatures
       ASSERT_NOEXCEPT(p1 == p2);
@@ -126,6 +129,9 @@
       ASSERT_NOEXCEPT(p1 <= p2);
       ASSERT_NOEXCEPT(p1 >  p2);
       ASSERT_NOEXCEPT(p1 >= p2);
+#if TEST_STD_VER > 17
+      ASSERT_NOEXCEPT(p1 <=> p2);
+#endif
     }
     { // check hash values
       auto h1 = hash_value(p1);
Index: libcxx/include/filesystem
===================================================================
--- libcxx/include/filesystem
+++ libcxx/include/filesystem
@@ -20,11 +20,12 @@
     size_t hash_value(const path& p) noexcept;
 
     bool operator==(const path& lhs, const path& rhs) noexcept;
-    bool operator!=(const path& lhs, const path& rhs) noexcept;
-    bool operator< (const path& lhs, const path& rhs) noexcept;
-    bool operator<=(const path& lhs, const path& rhs) noexcept;
-    bool operator> (const path& lhs, const path& rhs) noexcept;
-    bool operator>=(const path& lhs, const path& rhs) noexcept;
+    bool operator!=(const path& lhs, const path& rhs) noexcept;             // removed in C++20
+    bool operator< (const path& lhs, const path& rhs) noexcept;             // removed in C++20
+    bool operator<=(const path& lhs, const path& rhs) noexcept;             // removed in C++20
+    bool operator> (const path& lhs, const path& rhs) noexcept;             // removed in C++20
+    bool operator>=(const path& lhs, const path& rhs) noexcept;             // removed in C++20
+    strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept; // C++20
 
     path operator/ (const path& lhs, const path& rhs);
 
Index: libcxx/include/__filesystem/path.h
===================================================================
--- libcxx/include/__filesystem/path.h
+++ libcxx/include/__filesystem/path.h
@@ -1038,6 +1038,7 @@
   friend _LIBCPP_HIDE_FROM_ABI bool operator==(const path& __lhs, const path& __rhs) noexcept {
     return __lhs.__compare(__rhs.__pn_) == 0;
   }
+#if _LIBCPP_STD_VER <= 17
   friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const path& __lhs, const path& __rhs) noexcept {
     return __lhs.__compare(__rhs.__pn_) != 0;
   }
@@ -1053,6 +1054,11 @@
   friend _LIBCPP_HIDE_FROM_ABI bool operator>=(const path& __lhs, const path& __rhs) noexcept {
     return __lhs.__compare(__rhs.__pn_) >= 0;
   }
+#else // _LIBCPP_STD_VER <= 17
+  friend _LIBCPP_HIDE_FROM_ABI strong_ordering operator<=>(const path& __lhs, const path& __rhs) noexcept {
+    return __lhs.__compare(__rhs.__pn_) <=> 0;
+  }
+#endif // _LIBCPP_STD_VER <= 17
 
   friend _LIBCPP_HIDE_FROM_ABI path operator/(const path& __lhs, const path& __rhs) {
     path __result(__lhs);
Index: libcxx/docs/Status/SpaceshipProjects.csv
===================================================================
--- libcxx/docs/Status/SpaceshipProjects.csv
+++ libcxx/docs/Status/SpaceshipProjects.csv
@@ -74,7 +74,7 @@
 | chrono::leap_second
 | chrono::time_zone_link",A ``<chrono>`` implementation,Unassigned,|Not Started|
 | `[fs.filesystem.syn] <https://wg21.link/fs.filesystem.syn>`_,| `filesystem::space_info <https://reviews.llvm.org/D130861>`_,None,Adrian Vogelsgesang,|In Progress|
-| `[fs.path.nonmember] <https://wg21.link/fs.path.nonmember>`_,| `filesystem::path <https://reviews.llvm.org/D130859>`_,None,Adrian Vogelsgesang,|In Progress|
+| `[fs.path.nonmember] <https://wg21.link/fs.path.nonmember>`_,| `filesystem::path <https://reviews.llvm.org/D130859>`_,None,Adrian Vogelsgesang,|Complete|
 | `[fs.dir.entry.obs] <https://wg21.link/fs.dir.entry.obs>`_,| `filesystem::directory_entry <https://reviews.llvm.org/D130860>`_,None,Adrian Vogelsgesang,|In Progress|
 | `[re.submatch.op] <https://wg21.link/re.submatch.op>`_,| sub_match,None,Mark de Wever,|In Progress|
 | `[thread.thread.id] <https://wg21.link/thread.thread.id>`_,| thread::id,None,Unassigned,|Not Started|


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130859.449399.patch
Type: text/x-patch
Size: 4745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220802/2b7dda2c/attachment.bin>


More information about the libcxx-commits mailing list