isocpp / isocpp/CppCoreGuidelines

[C++20] C.86: Make == symmetric with respect to operand types

Open
#2,001 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

[intentionally ignoring "and noexcept" because it's unrelated]

As far as I understand, with C++20 rewritten expressions, an operator== defined as a member function is now symmetric and the assertion

B’s comparison accepts conversions for its second operand, but not its first.

in the guidelines does not hold anymore.

I would still teach people to define their operators as non-member because other operators are not symmetric and it's easier to have just one general rule "define operators as non-member functions".

But is my understand correct here ? If it is, do you agree we should change the wording of C.86 ?

Contributor guide

Open the contributing guide

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 with the current wording of guideline C.86 and the C++20 rules for rewritten comparison expressions. Confirm whether the stated asymmetry still applies, then determine whether the guideline needs revised wording. Done means the language-lawyer question is resolved and C.86 accurately reflects the decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.