[libcxx-commits] [libcxx] ec789a4 - [libc++] Add equality for spaceship types for themselves

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 18 07:23:05 PDT 2020


Author: Christopher Di Bella
Date: 2020-06-18T10:22:50-04:00
New Revision: ec789a41e296de552623b0e1836c70329ba85247

URL: https://github.com/llvm/llvm-project/commit/ec789a41e296de552623b0e1836c70329ba85247
DIFF: https://github.com/llvm/llvm-project/commit/ec789a41e296de552623b0e1836c70329ba85247.diff

LOG: [libc++] Add equality for spaceship types for themselves

- Adds operator==(partial_ordering, partial_ordering)
- Adds operator==(weak_ordering, weak_ordering)
- Adds operator==(strong_ordering, strong_ordering)

Differential Revision: https://reviews.llvm.org/D81823

Added: 
    

Modified: 
    libcxx/include/compare
    libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
    libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
    libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
    libcxx/www/cxx2a_status.html

Removed: 
    


################################################################################
diff  --git a/libcxx/include/compare b/libcxx/include/compare
index e05257bebfa5..717859a1e3af 100644
--- a/libcxx/include/compare
+++ b/libcxx/include/compare
@@ -43,6 +43,84 @@ namespace std {
   template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
   template<class T> constexpr strong_equality strong_equal(const T& a, const T& b);
   template<class T> constexpr weak_equality weak_equal(const T& a, const T& b);
+
+  // [cmp.partialord], Class partial_ordering
+  class partial_ordering {
+  public:
+    // valid values
+    static const partial_ordering less;
+    static const partial_ordering equivalent;
+    static const partial_ordering greater;
+    static const partial_ordering unordered;
+
+    // comparisons
+    friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
+    friend constexpr bool operator==(partial_ordering v, partial_ordering w) noexcept = default;
+    friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
+    friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
+    friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
+    friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
+    friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
+    friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
+    friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
+    friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
+    friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
+    friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
+  };
+
+  // [cmp.weakord], Class weak_ordering
+  class weak_ordering {
+  public:
+    // valid values
+    static const weak_ordering less;
+    static const weak_ordering equivalent;
+    static const weak_ordering greater;
+
+    // conversions
+    constexpr operator partial_ordering() const noexcept;
+
+    // comparisons
+    friend constexpr bool operator==(weak_ordering v, unspecified) noexcept;
+    friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
+    friend constexpr bool operator< (weak_ordering v, unspecified) noexcept;
+    friend constexpr bool operator> (weak_ordering v, unspecified) noexcept;
+    friend constexpr bool operator<=(weak_ordering v, unspecified) noexcept;
+    friend constexpr bool operator>=(weak_ordering v, unspecified) noexcept;
+    friend constexpr bool operator< (unspecified, weak_ordering v) noexcept;
+    friend constexpr bool operator> (unspecified, weak_ordering v) noexcept;
+    friend constexpr bool operator<=(unspecified, weak_ordering v) noexcept;
+    friend constexpr bool operator>=(unspecified, weak_ordering v) noexcept;
+    friend constexpr weak_ordering operator<=>(weak_ordering v, unspecified) noexcept;
+    friend constexpr weak_ordering operator<=>(unspecified, weak_ordering v) noexcept;
+  };
+
+  // [cmp.strongord], Class strong_ordering
+  class strong_ordering {
+  public:
+    // valid values
+    static const strong_ordering less;
+    static const strong_ordering equal;
+    static const strong_ordering equivalent;
+    static const strong_ordering greater;
+
+    // conversions
+    constexpr operator partial_ordering() const noexcept;
+    constexpr operator weak_ordering() const noexcept;
+
+    // comparisons
+    friend constexpr bool operator==(strong_ordering v, unspecified) noexcept;
+    friend constexpr bool operator==(strong_ordering v, strong_ordering w) noexcept = default;
+    friend constexpr bool operator< (strong_ordering v, unspecified) noexcept;
+    friend constexpr bool operator> (strong_ordering v, unspecified) noexcept;
+    friend constexpr bool operator<=(strong_ordering v, unspecified) noexcept;
+    friend constexpr bool operator>=(strong_ordering v, unspecified) noexcept;
+    friend constexpr bool operator< (unspecified, strong_ordering v) noexcept;
+    friend constexpr bool operator> (unspecified, strong_ordering v) noexcept;
+    friend constexpr bool operator<=(unspecified, strong_ordering v) noexcept;
+    friend constexpr bool operator>=(unspecified, strong_ordering v) noexcept;
+    friend constexpr strong_ordering operator<=>(strong_ordering v, unspecified) noexcept;
+    friend constexpr strong_ordering operator<=>(unspecified, strong_ordering v) noexcept;
+  };
 }
 */
 
@@ -248,6 +326,8 @@ public:
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
 
 #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
+  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering, partial_ordering) noexcept = default;
+
   _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
 #endif
@@ -364,6 +444,8 @@ public:
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
 
 #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
+  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering, weak_ordering) noexcept = default;
+
   _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
 #endif
@@ -490,6 +572,8 @@ public:
   _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
 
 #ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
+  _LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering, strong_ordering) noexcept = default;
+
   _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
   _LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
 #endif

diff  --git a/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
index 5d69dbb3d472..4ecfe21f06f8 100644
--- a/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.partialord/partialord.pass.cpp
@@ -150,6 +150,42 @@ constexpr bool test_constexpr() {
       break;
     }
   }
+  {
+    static_assert(std::partial_ordering::less == std::partial_ordering::less);
+    static_assert(std::partial_ordering::less !=
+                  std::partial_ordering::equivalent);
+    static_assert(std::partial_ordering::less !=
+                  std::partial_ordering::greater);
+    static_assert(std::partial_ordering::less !=
+                  std::partial_ordering::unordered);
+
+    static_assert(std::partial_ordering::equivalent !=
+                  std::partial_ordering::less);
+    static_assert(std::partial_ordering::equivalent ==
+                  std::partial_ordering::equivalent);
+    static_assert(std::partial_ordering::equivalent !=
+                  std::partial_ordering::greater);
+    static_assert(std::partial_ordering::equivalent !=
+                  std::partial_ordering::unordered);
+
+    static_assert(std::partial_ordering::greater !=
+                  std::partial_ordering::less);
+    static_assert(std::partial_ordering::greater !=
+                  std::partial_ordering::equivalent);
+    static_assert(std::partial_ordering::greater ==
+                  std::partial_ordering::greater);
+    static_assert(std::partial_ordering::greater !=
+                  std::partial_ordering::unordered);
+
+    static_assert(std::partial_ordering::unordered !=
+                  std::partial_ordering::less);
+    static_assert(std::partial_ordering::unordered !=
+                  std::partial_ordering::equivalent);
+    static_assert(std::partial_ordering::unordered !=
+                  std::partial_ordering::greater);
+    static_assert(std::partial_ordering::unordered ==
+                  std::partial_ordering::unordered);
+  }
 #endif
 
   return true;

diff  --git a/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
index bb2f3f2acf46..2a8f94940048 100644
--- a/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.strongord/strongord.pass.cpp
@@ -198,6 +198,20 @@ constexpr bool test_constexpr() {
       break;
     }
   }
+  {
+    static_assert(std::strong_ordering::less == std::strong_ordering::less);
+    static_assert(std::strong_ordering::less != std::strong_ordering::equal);
+    static_assert(std::strong_ordering::less != std::strong_ordering::greater);
+
+    static_assert(std::strong_ordering::equal != std::strong_ordering::less);
+    static_assert(std::strong_ordering::equal == std::strong_ordering::equal);
+    static_assert(std::strong_ordering::equal != std::strong_ordering::greater);
+
+    static_assert(std::strong_ordering::greater != std::strong_ordering::less);
+    static_assert(std::strong_ordering::greater != std::strong_ordering::equal);
+    static_assert(std::strong_ordering::greater ==
+                  std::strong_ordering::greater);
+  }
 #endif
 
   return true;

diff  --git a/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp b/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
index 39f18da845d7..d4fade6bb984 100644
--- a/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
+++ b/libcxx/test/std/language.support/cmp/cmp.weakord/weakord.pass.cpp
@@ -155,6 +155,23 @@ constexpr bool test_constexpr() {
       break;
     }
   }
+
+  {
+    static_assert(std::weak_ordering::less == std::weak_ordering::less);
+    static_assert(std::weak_ordering::less != std::weak_ordering::equivalent);
+    static_assert(std::weak_ordering::less != std::weak_ordering::greater);
+
+    static_assert(std::weak_ordering::equivalent != std::weak_ordering::less);
+    static_assert(std::weak_ordering::equivalent ==
+                  std::weak_ordering::equivalent);
+    static_assert(std::weak_ordering::equivalent !=
+                  std::weak_ordering::greater);
+
+    static_assert(std::weak_ordering::greater != std::weak_ordering::less);
+    static_assert(std::weak_ordering::greater !=
+                  std::weak_ordering::equivalent);
+    static_assert(std::weak_ordering::greater == std::weak_ordering::greater);
+  }
 #endif
 
   return true;

diff  --git a/libcxx/www/cxx2a_status.html b/libcxx/www/cxx2a_status.html
index 6214dd2cdd83..5a520f185c26 100644
--- a/libcxx/www/cxx2a_status.html
+++ b/libcxx/www/cxx2a_status.html
@@ -182,7 +182,7 @@ <h3>Paper Status</h3>
 	<tr><td><a href="https://wg21.link/P1522">P1522</a></td><td>LWG</td><td>Iterator Difference Type and Integer Overflow</td><td>Cologne</td><td></td><td></td></tr>
 	<tr><td><a href="https://wg21.link/P1523">P1523</a></td><td>LWG</td><td>Views and Size Types</td><td>Cologne</td><td></td><td></td></tr>
 	<tr><td><a href="https://wg21.link/P1612">P1612</a></td><td>LWG</td><td>Relocate Endian’s Specification</td><td>Cologne</td><td>Complete</td><td>10.0</td></tr>
-	<tr><td><a href="https://wg21.link/P1614">P1614</a></td><td>LWG</td><td>The Mothership has Landed</td><td>Cologne</td><td></td><td></td></tr>
+	<tr><td><a href="https://wg21.link/P1614">P1614</a></td><td>LWG</td><td>The Mothership has Landed</td><td>Cologne</td><td><i>In progress</i></td><td></td></tr>
 	<tr><td><a href="https://wg21.link/P1638">P1638</a></td><td>LWG</td><td>basic_istream_view::iterator should not be copyable</td><td>Cologne</td><td></td><td></td></tr>
 	<tr><td><a href="https://wg21.link/P1643">P1643</a></td><td>LWG</td><td>Add wait/notify to atomic_ref</td><td>Cologne</td><td></td><td></td></tr>
 	<tr><td><a href="https://wg21.link/P1644">P1644</a></td><td>LWG</td><td>Add wait/notify to atomic<shared_ptr></td><td>Cologne</td><td></td><td></td></tr>


        


More information about the libcxx-commits mailing list