Skip to content

Conversation

@jafar75
Copy link
Contributor

@jafar75 jafar75 commented Jan 3, 2025

Extend uint types with support for three-way comparison operator (<=>).

Closes #295.

@jafar75
Copy link
Contributor Author

jafar75 commented Jan 5, 2025

@chfast I've no idea why gcc-santizers failing in tests, unrelated to this PR

@chfast
Copy link
Owner

chfast commented Jan 8, 2025

Please rebase your PR. The CI build issue should be resolved.

Copy link
Owner

@chfast chfast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this work.

The main motivation for this is to make usage like below compile and work as expected.

struct W
{
    intx::uint256 v;

    friend auto operator<=>(W, W) = default;
};

See https://godbolt.org/z/aq6TEjqqs for editable examples.

This doesn't work however. I believe the reason is that using int as the result type has some limiting effects. We probably should return std::strong_ordering. Maybe reading more of the C++ reference can clarify this.

At least, please add some unit tests like in these examples and try returning std::strong_ordering.

@jafar75
Copy link
Contributor Author

jafar75 commented Jan 9, 2025

@chfast, thanks for the review.
I switched to strong_ordering in my local and the test in godbolt got passed. will push the changes soon.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 9, 2025

@chfast chfast changed the title add support for c++20 spaceship operator Add support for c++20 spaceship operator <=> Jan 9, 2025
@chfast chfast merged commit 2f81aad into chfast:master Jan 9, 2025
18 checks passed
@chfast
Copy link
Owner

chfast commented Jan 9, 2025

Thanks a lot.

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.

Add support for operator <=>

2 participants