[libcxx-commits] [libcxx] WIP - [libc++][functional] P2944R3 (partial): Comparisons for ``reference_wrapper`` (``reference_wrapper`` operators only) (PR #88384)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Apr 28 22:17:41 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;
----------------
H-G-Hristov wrote:
> In practice the requires-clause can be implemented more simply (and efficiently) by checking the constraints of synth-three-way directly:
>
> `requires (const T t) { { t < t } -> boolean-testable; }`
>
>but when specified in prose in a Constraints: element it seems clearer to just use synth-three-way(x.get(), y.get()).
https://github.com/llvm/llvm-project/pull/88384
More information about the libcxx-commits
mailing list