-
Notifications
You must be signed in to change notification settings - Fork 786
Description
Background
[class.eq] currently reads:
The return value
V
of a defaulted==
operator function with parametersx
andy
is determined by comparing corresponding elements$x_i$ and$y_i$ in the expanded lists of subobjects forx
andy
(in increasing index order) until the first index$i$ where$x_i == y_i$ yields a result value which, when contextually converted tobool
, yieldsfalse
.
If no such index exists,V
istrue
.
Otherwise,V
isfalse
.
The first long sentence describes the side effects of calling a defaulted operator==
, while the other two sentences describe the return value.
This is unambiguous, but I think the wording could be improved.
Problem
At first glance this might be interpreted in a way that describes three distinct cases. In that case it's hard to make sense of the "Otherwise, V
is false.
" sentence, as seemingly the previous sentences cover all cases.
This came up on the std-discussion mailing list: https://lists.isocpp.org/std-discussion/2022/12/1927.php
Some proposals for rewording
- Mirror the wording of [class.spaceship]:
...when contextually converted to
bool
, yieldsfalse
;
V
isfalse
.
If no such index exists,V
istrue
.
- Switch around the last two sentences:
..when contextually converted to
bool
, yieldsfalse
.
If such index exists,V
isfalse
.
Otherwise,V
istrue
.
Some other considerations
Even though the first long sentence describes the side effects of calling a defaulted operator==
, it leads in with "The return value V
of a defaulted ==
operator function with parameters x
and y
is determined...". It might be better to reword the first sentence in a way that doesn't mention the return value yet. One such wording would be, combined with the second suggestion above:
When a defaulted
==
operator function is called with parametersx
andy
then the corresponding elemnts$x_i$ and$y_i$ in the expanded lists of subobjects forx
andy
(in increasing index order) are compared until the first index$i$ where$x_i == y_i$ yields a result value which, when contextually converted tobool
, yieldsfalse
.
If such index exists, the return value isfalse
.
Otherwise, the return value istrue
.
[class.spaceship] can have similar treatment.