Skip to content

Commit d86472a

Browse files
committed
libstdc++: Simplify constraints on <=> for std::reference_wrapper
Instead of constraining these overloads in terms of synth-three-way we can just check that the value_type is less-than-comparable, which is what synth-three-way's constraints check. The reason that I implemented these with constraints has now been filed as LWG 4071, so add a comment about that too. libstdc++-v3/ChangeLog: * include/bits/refwrap.h (operator<=>): Simplify constraints.
1 parent eed7fb1 commit d86472a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

libstdc++-v3/include/bits/refwrap.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,23 +384,29 @@ _GLIBCXX_MEM_FN_TRAITS(&& noexcept, false_type, true_type)
384384
&& requires { { __x.get() == __y.get() } -> convertible_to<bool>; }
385385
{ return __x.get() == __y.get(); }
386386

387+
// _GLIBCXX_RESOLVE_LIB_DEFECTS
388+
// 4071. reference_wrapper comparisons are not SFINAE-friendly
389+
387390
[[nodiscard]]
388391
friend constexpr auto
389-
operator<=>(reference_wrapper __x, reference_wrapper<_Tp> __y)
390-
requires requires { __detail::__synth3way(__x.get(), __y.get()); }
392+
operator<=>(reference_wrapper __x, reference_wrapper __y)
393+
requires requires (const _Tp __t) {
394+
{ __t < __t } -> __detail::__boolean_testable;
395+
}
391396
{ return __detail::__synth3way(__x.get(), __y.get()); }
392397

393398
[[nodiscard]]
394399
friend constexpr auto
395400
operator<=>(reference_wrapper __x, const _Tp& __y)
396-
requires requires { __detail::__synth3way(__x.get(), __y); }
401+
requires requires { { __y < __y } -> __detail::__boolean_testable; }
397402
{ return __detail::__synth3way(__x.get(), __y); }
398403

399404
[[nodiscard]]
400405
friend constexpr auto
401406
operator<=>(reference_wrapper __x, reference_wrapper<const _Tp> __y)
402-
requires (!is_const_v<_Tp>)
403-
&& requires { __detail::__synth3way(__x.get(), __y.get()); }
407+
requires (!is_const_v<_Tp>) && requires (const _Tp __t) {
408+
{ __t < __t } -> __detail::__boolean_testable;
409+
}
404410
{ return __detail::__synth3way(__x.get(), __y.get()); }
405411
#endif
406412
};

0 commit comments

Comments
 (0)