Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eq and ne operators for compare utility. #863

Conversation

Benzinnos
Copy link
Contributor

No description provided.

Copy link

Review changes with SemanticDiff.

Copy link
Contributor

@jwellbelove jwellbelove left a comment

Choose a reason for hiding this comment

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

Maybe add the '<=>' operator for C++20 too?

@Benzinnos
Copy link
Contributor Author

Maybe add the '<=>' operator for C++20 too?

  1. So, are we really need spaceship operator? What the use case? We have already all 6 comparing operators.
  2. If we are need this, possible implementations:
typedef int cmp_result_type;

static cmp_result_type cmp(first_argument_type lhs, second_argument_type rhs)
{
  if (lt(lhs, rhs)) {
    return -1;
  }

 if (gt(lhs, rhs)) {
    return 1;
  }

  return 0;
}

Or, if we can use std::*_ordering types:

typedef std::strong_ordering cmp_result_type;

static cmp_result_type cmp(first_argument_type lhs, second_argument_type rhs)
{
  if (lt(lhs, rhs)) {
    return std::strong_ordering::less;
  }

  if (gt(lhs, rhs)) {
    return std::strong_ordering::greater;
  }

  return std::strong_ordering::equivalent;
}

@jwellbelove
Copy link
Contributor

So, are we really need spaceship operator? What the use case? We have already all 6 comparing operators.
Well, the struct is called 'compare' and I thought that the three way compare would be the only one missing from the set after this change.

@jwellbelove jwellbelove changed the base branch from master to pull-request/#863-Add-eq-and-ne-operators-for-compare-utility March 15, 2024 13:03
@jwellbelove jwellbelove merged commit 80af5a4 into ETLCPP:pull-request/#863-Add-eq-and-ne-operators-for-compare-utility Mar 15, 2024
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.

2 participants