Skip to content

Commit cb1c668

Browse files
committed
C++20 now considers equality to be commutable (A == B) === (B == A)
This means that the operator must be const so that swapping is allowed.
1 parent 71527f5 commit cb1c668

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

Algorithm/test/pageparser.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct ClusterData {
5050
{
5151
}
5252

53-
bool operator==(const ClusterData& rhs)
53+
bool operator==(const ClusterData& rhs) const
5454
{
5555
return clusterid == rhs.clusterid && x == rhs.x && y == rhs.y && z == rhs.z && e == rhs.e;
5656
}

DataFormats/Headers/include/Headers/DataHeader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ struct Descriptor {
286286
bool operator<(const Descriptor& other) const { return std::memcmp(this->str, other.str, N) < 0; }
287287
bool operator!=(const Descriptor& other) const { return not this->operator==(other); }
288288

289+
// Convesion operators for comparison with their implicitly convertible types
290+
friend bool operator==(const Descriptor& lhs, ImplicitConversion rhs) { return static_cast<ImplicitConversion>(lhs) == rhs; }
289291
// explicitly forbid comparison with e.g. const char* strings
290292
// use: value == Descriptor<N>("DESC") for the appropriate
291293
// template instantiation instead

Framework/Core/test/test_ASoA.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ TEST_CASE("TestTableIteration")
147147

148148
b = tests2.begin();
149149
REQUIRE(b != e);
150-
REQUIRE((b + 1) == (b + 1));
151-
REQUIRE((b + 7) != b);
152-
REQUIRE((b + 7) != e);
153-
REQUIRE((b + 8) == e);
150+
REQUIRE(((b + 1) == (b + 1)));
151+
REQUIRE(((b + 7) != b));
152+
REQUIRE(((b + 7) != e));
153+
REQUIRE(((b + 8) == e));
154154

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

0 commit comments

Comments
 (0)