Skip to content

Conversation

@20162026
Copy link
Collaborator

@20162026 20162026 commented May 6, 2025

reimplement <=> as the previous implementation was questionable and failed in some cases.

based on rules described at: https://en.cppreference.com/w/cpp/container/inplace_vector/operator_cmp

@20162026 20162026 requested a review from a team May 6, 2025 15:38
@wusatosi
Copy link
Member

wusatosi commented May 6, 2025

Thank you for your contribution! I will review this later!

Copy link
Member

@JeffGarland JeffGarland left a comment

Choose a reason for hiding this comment

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

I'm going to approve this PR -- I'll trust you to make any additional changes as you see fit and merging. Good work actually fixing this since it was just wrong. Welcome @20162026 and thanks for your contribution!

@20162026
Copy link
Collaborator Author

20162026 commented May 7, 2025

Just noticed that my suggestion will not properly handle unorderable values eg. nan("") == nan("").
I will try to come up with a better solution tomorrow

@JeffGarland
Copy link
Member

I think the pre-conditions here mean that if you have nans you're in violation and it's UB

@20162026
Copy link
Collaborator Author

20162026 commented May 8, 2025

I understand precondition as: T models three_way_comparable OR (< is defined for values of type T and < is a total ordering relationship)

nan (float/double) is three_way_comparable with std::partial_ordering, furthermore std::vector nan compare results in std::partial_ordering::unordered

@wusatosi
Copy link
Member

wusatosi commented May 8, 2025

failed in some cases.

Can you list out cases that fails with the original implementation?
Those could be great unit tests!

@20162026
Copy link
Collaborator Author

20162026 commented May 8, 2025

failed in some cases.

Can you list out cases that fails with the original implementation? Those could be great unit tests!

almost all of the issues I could think of are already covered by tests.
But to name a few, original:

  • did size compare before value compare
  • had incorrect return type
  • would not work with unorderable values
  • did not check T preconditions
  • did not break the loop after finding the first nonequal element

@wusatosi
Copy link
Member

wusatosi commented May 8, 2025

failed in some cases.

Can you list out cases that fails with the original implementation? Those could be great unit tests!

almost all of the issues I could think of are already covered by tests.
But to name a few, original:

  • did size compare before value compare
  • had incorrect return type
  • would not work with unorderable values
  • did not check T preconditions
  • did not break the loop after finding the first nonequal element

Oh I didn't realize you added test as well!! This is fantastic!

Copy link
Member

@wusatosi wusatosi left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. As I understand you still have some progress to make, feel free to @wusatosi to notify me once you're done, I can also approve so you can do that in a separate PR.

Again thank you so much for your contribution!

@20162026
Copy link
Collaborator Author

20162026 commented May 8, 2025

@wusatosi Im done with the changes


template <class T>
concept lessthan_comparable =
beman::details::inplace_vector::lessthan_comparable<T>;
Copy link
Member

Choose a reason for hiding this comment

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

It strikes me that the namespace is backwards here -- should be beman::inplace_vector::detail -- but that's an existing issue of course. And maybe something we don't address clearly in the standard.

Copy link
Member

Choose a reason for hiding this comment

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

I might be wrong here, but beman::inplace_vector clashes with the inplace_vector struct under the beman namespace.

Copy link
Member

@wusatosi wusatosi left a comment

Choose a reason for hiding this comment

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

Good job!

@wusatosi wusatosi merged commit 00c10c3 into bemanproject:main May 10, 2025
25 checks passed
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.

3 participants