#
Affected subclause: [over.match.oper]
Change: Equality and inequality expressions can now find reversed and rewritten candidates.

Rationale: Improve consistency of equality with three-way comparison and make it easier to write the full complement of equality operations.

Effect on original feature: For certain pairs of types where one is convertible to the other, equality or inequality expressions between an object of one type and an object of the other type invoke a different operator.
Also, for certain types, equality or inequality expressions between two objects of that type become ambiguous.
[Example 1: struct A { operator int() const; }; bool operator=(A, int); / #1 / #2 is built-in candidate: bool operator==(int, int); / #3 is built-in candidate: bool operator!=(int, int); int check(A x, A y) { return (x == y) + / ill-formed; previously well-formed (10 == x) + / calls #1, previously selected #2 (10 != x); / calls #1, previously selected #3 } — end example]
Affected subclause: [over.match.oper]
Change: Overload resolution may change for equality operators ([expr.eq]).

Rationale: Support calling operator= with reversed order of arguments.

Effect on original feature: Valid C++ 2017 code that uses equality operators with conversion functions may be ill-formed or have different semantics in this revision of C++.
[Example 2: struct A { operator int() const { return 10; } }; bool operator=(A, int); / #1 / #2 is built-in candidate: bool operator==(int, int); bool b = 10 == A(); / calls #1 with reversed order of arguments; previously selected #2 struct B { bool operator=(const B&); / member function with no cv-qualifier }; B b1; bool eq = (b1 == b1); / ambiguous; previously well-formed — end example]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant