[libcxx-commits] [PATCH] D130838: [libc++] Implement `operator<=>` for `unique_ptr`

Adrian Vogelsgesang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 4 11:52:44 PDT 2022


avogelsgesang added inline comments.


================
Comment at: libcxx/include/memory:509
+    bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);    // removed in C++20
 template <class T1, class D1, class T2, class D2>
     bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
----------------
Mordante wrote:
> Interesting these aren't removed, including in the WP.
I agree. The revision history of P1614R2 states

>The comparisons between unique_ptr<T, D> and nullptr were originally removed and replaced with a <=>, but this was reverted.

But I don't know where to find the history on why that change was made



================
Comment at: libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/cmp.pass.cpp:72
+#if TEST_STD_VER > 17
+  AssertOrderReturn<std::strong_ordering, std::unique_ptr<int>>();
+#endif
----------------
Mordante wrote:
> Can you also test with the other two comparison categories? Not 100% sure it's even possible.
I don't understand.

`unique_ptr <=> unique_ptr` is specified to return `std::strong_ordering`. If I added, e.g.,

> AssertOrderReturn<std::weak_ordering, std::unique_ptr<int>>();

this test would fail because the result of `unique_ptr <=> unique_ptr` is strong_ordering, not weak_ordering


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130838



More information about the libcxx-commits mailing list