Skip to content

refactor: Use comparison operator in comparison overloads - #2581

Open
rprospero wants to merge 4 commits into
develop2from
comparison_operator
Open

refactor: Use comparison operator in comparison overloads#2581
rprospero wants to merge 4 commits into
develop2from
comparison_operator

Conversation

@rprospero

Copy link
Copy Markdown
Contributor

C++20 added the comparison operator (sometimes referred to as the spaceship operator), from which all of the other comparison operators can be derived. I've used this to cut down on a bunch of the boiler plate in our iterator overloads and for our Number type.

There's one change in the handling of NaN for the Number class. For any floating point value x, the following statements are always true under the new setup, but were always false under the old setup:

a < NaN
Nan < a

This was done to allow strong ordering of Number, despite floating point values only having weak ordering. This convention was chosen to preserve the the following three relations, which I considered more fundamental:

a != NaN
NaN != a
NaN != Nan

@rprospero
rprospero marked this pull request as ready for review August 20, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant