From 7eeaf87153d0f2ed6bb358292bc26b5b7e0eea86 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Tue, 7 Nov 2023 13:12:45 +0100 Subject: [PATCH] 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. --- Algorithm/test/pageparser.cxx | 2 +- DataFormats/Headers/include/Headers/DataHeader.h | 2 ++ Framework/Core/test/test_ASoA.cxx | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Algorithm/test/pageparser.cxx b/Algorithm/test/pageparser.cxx index 14b24c670cfd6..7551c32d9d864 100644 --- a/Algorithm/test/pageparser.cxx +++ b/Algorithm/test/pageparser.cxx @@ -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; } diff --git a/DataFormats/Headers/include/Headers/DataHeader.h b/DataFormats/Headers/include/Headers/DataHeader.h index ed25d0d7f5082..a4d3abdba65c7 100644 --- a/DataFormats/Headers/include/Headers/DataHeader.h +++ b/DataFormats/Headers/include/Headers/DataHeader.h @@ -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(lhs) == rhs; } // explicitly forbid comparison with e.g. const char* strings // use: value == Descriptor("DESC") for the appropriate // template instantiation instead diff --git a/Framework/Core/test/test_ASoA.cxx b/Framework/Core/test/test_ASoA.cxx index e6a537dab3dc9..467b15ec5bde0 100644 --- a/Framework/Core/test/test_ASoA.cxx +++ b/Framework/Core/test/test_ASoA.cxx @@ -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);