[libcxx-commits] [libcxx] WIP - [libc++][functional] P2944R3 (partial): Comparisons for ``reference_wrapper`` (``reference_wrapper`` operators only) (PR #88384)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Apr 28 19:21:09 PDT 2024
================
@@ -64,6 +67,62 @@ class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> {
{
return std::__invoke(get(), std::forward<_ArgTypes>(__args)...);
}
+
+#if _LIBCPP_STD_VER >= 26
+
+ // [refwrap.comparisons], comparisons
+
+ friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y)
+ requires requires {
+ { __x.get() == __y.get() } -> __boolean_testable;
+ }
+ {
+ return __x.get() == __y.get();
+ }
+
+ friend constexpr bool operator==(reference_wrapper __x, const _Tp& __y)
+ requires requires {
+ { __x.get() == __y } -> __boolean_testable;
+ }
+ {
+ return __x.get() == __y;
+ }
+
+ friend constexpr bool operator==(reference_wrapper __x, reference_wrapper<const _Tp> __y)
+ requires(!is_const_v<_Tp>) && requires {
+ { __x.get() == __y.get() } -> __boolean_testable;
+ }
+ {
+ return __x.get() == __y.get();
+ }
+
+ // `operator<=>`: Checks the constraints of `synth-three-way` as per https://wg21.link/LWG4071 directly
+
+ friend constexpr auto operator<=>(reference_wrapper __x, reference_wrapper __y)
+ requires requires(const _Tp t) {
+ { t < t } -> __boolean_testable;
----------------
frederick-vs-ja wrote:
See https://github.com/gcc-mirror/gcc/commit/d86472a6f041ccf3d1be0cf6bb15d1e0ad8f6dbe. This approach is also suggested [LWG4071](https://cplusplus.github.io/LWG/issue4071) as an equivalent but simpler implementation stategy.
https://github.com/llvm/llvm-project/pull/88384
More information about the libcxx-commits
mailing list