[libcxx-commits] [libcxx] [libc++] Specialize __lazy_synth_three_way_comparator for std::greater and friends (PR #157624)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 10 08:45:18 PDT 2025


================
@@ -85,6 +85,23 @@ struct __lazy_synth_three_way_comparator<_Comparator,
   }
 };
 
+template <class _Comparator, class _LHS, class _RHS>
+struct __lazy_synth_three_way_comparator<_Comparator,
+                                         _LHS,
+                                         _RHS,
+                                         __enable_if_t<__desugars_to_v<__greater_tag, _Comparator, _LHS, _RHS> &&
+                                                       __has_default_three_way_comparator_v<_LHS, _RHS> > > {
+  // This lifetimebound annotation is technically incorrect, but other specializations actually capture the lifetime of
+  // the comparator.
+  _LIBCPP_HIDE_FROM_ABI __lazy_synth_three_way_comparator(_LIBCPP_CTOR_LIFETIMEBOUND const _Comparator&) {}
----------------
ldionne wrote:

Let's add a test with the associative containers and `std::greater`. You might want to introduce a bug in this patch and check which tests are failing, if any. That would inform what tests we might want to add.

I'd suggest that for each associative container, we add a test that instantiates it with `std::greater`, inserts a few elements, makes sure we can find them, and then tests the iteration order.

https://github.com/llvm/llvm-project/pull/157624


More information about the libcxx-commits mailing list