ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.04k stars 371 forks source link

Add eq and ne operators for compare utility. #863

Closed Benzinnos closed 3 months ago

semanticdiff-com[bot] commented 3 months ago

Review changes with SemanticDiff.

Benzinnos commented 3 months ago

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:

```cpp
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 commented 3 months ago

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.