[libcxx-commits] [libcxx] [libc++] Specialize __lazy_synth_three_way_comparator for std::greater and friends (PR #157624)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 10 08:42:14 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Nikolas Klauser (philnik777)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/157624.diff
1 Files Affected:
- (modified) libcxx/include/__utility/lazy_synth_three_way_comparator.h (+17)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/157624
More information about the libcxx-commits
mailing list