From 06a1c6980426a5a4140fb554271f4d16f1e18666 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 26 Sep 2026 13:38:52 +0200 Subject: [PATCH] Compare the test object type's entries with std::all_of clang-tidy (readability-use-anyofallof) asked for std::all_of instead of the loop in unordered_object_t's operator==. The entry type is spelled out, as C++11 needs typename for base_type::value_type and C++20 reports it as redundant. Signed-off-by: Niels Lohmann --- tests/src/unit-comparison.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/src/unit-comparison.cpp b/tests/src/unit-comparison.cpp index 303ac631b..5c2118c9b 100644 --- a/tests/src/unit-comparison.cpp +++ b/tests/src/unit-comparison.cpp @@ -15,9 +15,12 @@ #include "doctest_compatibility.h" +#include + #include #include #include +#include #include #define JSON_TESTS_PRIVATE @@ -777,19 +780,11 @@ struct unordered_object_t : std::map, Allocator> friend bool operator==(const unordered_object_t& lhs, const unordered_object_t& rhs) { - if (lhs.size() != rhs.size()) - { - return false; - } - for (const auto& entry : lhs) + return lhs.size() == rhs.size() && std::all_of(lhs.begin(), lhs.end(), [&rhs](const std::pair& entry) { const auto it = rhs.find(entry.first); - if (it == rhs.end() || !(it->second == entry.second)) - { - return false; - } - } - return true; + return it != rhs.end() && it->second == entry.second; + }); } friend bool operator!=(const unordered_object_t& lhs, const unordered_object_t& rhs)