C++ Logo

std-discussion

Advanced search

Re: tuple<X>::op<=> too eager to disregard X::op<=>

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 12 Feb 2021 19:38:35 -0500
On Fri, Feb 12, 2021 at 2:49 PM Roman Odaisky via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> Hi All,
>
> If a class has a user-defined operator <=>, but no other comparison operators,
> specifically, no operator ==, then the operator <=> of tuples and containers
> will quietly fall back to the (auto-generated) operator <, in the end still
> invoking operator <=> but up to twice as many times as necessary.
>
> This is because synth-three-way (http://eel.is/c++draft/expos.only.func) is
> defined as only using <=> if three_way_comparable_with is satisfied, which
> requires _all_ the comparison operators.
>
> Is it intentional that std::tuple<X>::operator <=> should be so averse to
> using X::operator <=>?
>
> I’m aware that defining operator <=> but not operator == is contrary to best
> practices, but silent pessimization does not seem to be an adequate
> punishment.

How about compilers or `std::tuple` implementations start warning
about it? That is, if a type can be `<=>` compared but not `==`
compared, then a warning can be emitted.

Received on 2021-02-12 18:38:48