Skip to content

Commit

Permalink
C++20 now considers equality to be commutable (A == B) === (B == A)
Browse files Browse the repository at this point in the history
This means that the operator must be const so that swapping is allowed.
  • Loading branch information
ktf committed Nov 7, 2023
1 parent bf3ac49 commit 7eeaf87
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Algorithm/test/pageparser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct ClusterData {
{
}

bool operator==(const ClusterData& rhs)
bool operator==(const ClusterData& rhs) const
{
return clusterid == rhs.clusterid && x == rhs.x && y == rhs.y && z == rhs.z && e == rhs.e;
}
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Headers/include/Headers/DataHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ struct Descriptor {
bool operator<(const Descriptor& other) const { return std::memcmp(this->str, other.str, N) < 0; }
bool operator!=(const Descriptor& other) const { return not this->operator==(other); }

// Convesion operators for comparison with their implicitly convertible types
friend bool operator==(const Descriptor& lhs, ImplicitConversion rhs) { return static_cast<ImplicitConversion>(lhs) == rhs; }
// explicitly forbid comparison with e.g. const char* strings
// use: value == Descriptor<N>("DESC") for the appropriate
// template instantiation instead
Expand Down
8 changes: 4 additions & 4 deletions Framework/Core/test/test_ASoA.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ TEST_CASE("TestTableIteration")

b = tests2.begin();
REQUIRE(b != e);
REQUIRE((b + 1) == (b + 1));
REQUIRE((b + 7) != b);
REQUIRE((b + 7) != e);
REQUIRE((b + 8) == e);
REQUIRE(((b + 1) == (b + 1)));
REQUIRE(((b + 7) != b));
REQUIRE(((b + 7) != e));
REQUIRE(((b + 8) == e));

for (auto& t : tests2) {
REQUIRE(t.x() == value / 4);
Expand Down

0 comments on commit 7eeaf87

Please sign in to comment.