cplusplus / cplusplus/draft

Clarify wording of [class.eq]

Open
#6,036 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

Background

[class.eq] currently reads:

The return value V of a defaulted == operator function with parameters x and y is determined by comparing corresponding elements $x_i$ and $y_i$ in the expanded lists of subobjects for x and y (in increasing index order) until the first index $i$ where $x_i == y_i$ yields a result value which, when contextually converted to bool, yields false.
If no such index exists, V is true.
Otherwise, V is false.

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
  1. Mirror the wording of [class.spaceship]:

...when contextually converted to bool, yields false;
V is false.
If no such index exists, V is true.

  1. Switch around the last two sentences:

..when contextually converted to bool, yields false.
If such index exists, V is false.
Otherwise, V is true.

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 parameters x and y then the corresponding elemnts $x_i$ and $y_i$ in the expanded lists of subobjects for x and y (in increasing index order) are compared until the first index $i$ where $x_i == y_i$ yields a result value which, when contextually converted to bool, yields false.
If such index exists, the return value is false.
Otherwise, the return value is true.

[class.spaceship] can have similar treatment.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in source/classes.tex at [class.eq], then compare its wording with [class.spaceship] and the linked std-discussion thread. Clarify the description of defaulted operator== evaluation and return values, resolving the proposed alternatives; done means the standard wording is unambiguous and consistent with the related section.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.