[libcxx-commits] [PATCH] D146545: [libc++] Module fixes for __synth_three_way.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 21 10:07:58 PDT 2023


Mordante created this revision.
Herald added a subscriber: mikhail.ramalho.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

These changes make it possible to use __synth_three_way in modules. The
change from a lambda to a function is a Clang issue.

The change is list was needed since the compiler couldn't deduce the
comparison template argument.

Adds a few missing includes too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146545

Files:
  libcxx/include/__compare/synth_three_way.h
  libcxx/include/compare
  libcxx/include/list


Index: libcxx/include/list
===================================================================
--- libcxx/include/list
+++ libcxx/include/list
@@ -185,6 +185,7 @@
 
 #include <__algorithm/comp.h>
 #include <__algorithm/equal.h>
+#include <__compare/synth_three_way.h>
 #include <__algorithm/lexicographical_compare.h>
 #include <__algorithm/lexicographical_compare_three_way.h>
 #include <__algorithm/min.h>
@@ -2349,7 +2350,7 @@
 operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y)
 {
     return std::lexicographical_compare_three_way(
-        __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way);
+        __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Tp, _Tp>);
 }
 
 #endif // _LIBCPP_STD_VER <= 17
Index: libcxx/include/compare
===================================================================
--- libcxx/include/compare
+++ libcxx/include/compare
@@ -151,6 +151,7 @@
 #include <__compare/ordering.h>
 #include <__compare/partial_order.h>
 #include <__compare/strong_order.h>
+#include <__compare/synth_three_way.h>
 #include <__compare/three_way_comparable.h>
 #include <__compare/weak_order.h>
 #include <__config>
Index: libcxx/include/__compare/synth_three_way.h
===================================================================
--- libcxx/include/__compare/synth_three_way.h
+++ libcxx/include/__compare/synth_three_way.h
@@ -25,21 +25,26 @@
 
 // [expos.only.func]
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
-  []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
-    requires requires {
-      { __t < __u } -> __boolean_testable;
-      { __u < __t } -> __boolean_testable;
-    }
-  {
-    if constexpr (three_way_comparable_with<_Tp, _Up>) {
-      return __t <=> __u;
-    } else {
-      if (__t < __u) return weak_ordering::less;
-      if (__u < __t) return weak_ordering::greater;
-      return weak_ordering::equivalent;
-    }
-  };
+// TODO MODULES restore the lamba to match the Standard.
+//_LIBCPP_HIDE_FROM_ABI inline constexpr auto __synth_three_way =
+//  []<class _Tp, class _Up>(const _Tp& __t, const _Up& __u)
+template <class _Tp, class _Up>
+_LIBCPP_HIDE_FROM_ABI constexpr auto __synth_three_way(const _Tp& __t, const _Up& __u)
+  requires requires {
+    { __t < __u } -> __boolean_testable;
+    { __u < __t } -> __boolean_testable;
+  }
+{
+  if constexpr (three_way_comparable_with<_Tp, _Up>) {
+    return __t <=> __u;
+  } else {
+    if (__t < __u)
+      return weak_ordering::less;
+    if (__u < __t)
+      return weak_ordering::greater;
+    return weak_ordering::equivalent;
+  }
+}
 
 template <class _Tp, class _Up = _Tp>
 using __synth_three_way_result = decltype(std::__synth_three_way(std::declval<_Tp&>(), std::declval<_Up&>()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146545.507032.patch
Type: text/x-patch
Size: 2787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230321/5877160c/attachment-0001.bin>


More information about the libcxx-commits mailing list