[libcxx-commits] [libcxx] [libc++] Specialize __lazy_synth_three_way_comparator for std::greater and friends (PR #157624)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 9 00:51:57 PDT 2025
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/157624
This specializes `__lazy_synth_three_way_comparator` to forward to `__default_three_way_comparator` if the comparator desugars to `__greater_tag`. This is the same as the desugaring to `__less_tag` except that the sign has to be inverted.
>From 80a18e3d405a47bc5c961170381db0a8eaece828 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 9 Sep 2025 09:50:05 +0200
Subject: [PATCH] [libc++] Specialize __lazy_synth_three_way_comparator for
std::greater and friends
---
.../__utility/lazy_synth_three_way_comparator.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/libcxx/include/__utility/lazy_synth_three_way_comparator.h b/libcxx/include/__utility/lazy_synth_three_way_comparator.h
index ca98845f04191..635dee1f7e4cb 100644
--- a/libcxx/include/__utility/lazy_synth_three_way_comparator.h
+++ b/libcxx/include/__utility/lazy_synth_three_way_comparator.h
@@ -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&) {}
+
+ // Same comment as above.
+ _LIBCPP_HIDE_FROM_ABI static __eager_compare_result
+ operator()(_LIBCPP_LIFETIMEBOUND const _LHS& __lhs, _LIBCPP_LIFETIMEBOUND const _RHS& __rhs) {
+ return __eager_compare_result(-__default_three_way_comparator<_LHS, _RHS>()(__lhs, __rhs));
+ }
+};
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___UTILITY_LAZY_SYNTH_THREE_WAY_COMPARATOR_H
More information about the libcxx-commits
mailing list