From 596028c46099801a9b8c99bd06fceae6288222cc Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 2 Nov 2026 17:54:39 +0100 Subject: [PATCH] Drop the null_result parameter JSON_IMPLEMENT_OPERATOR no longer uses (#6005) Without the same-type scalar cases, the macro body has no use for it, and JSON_IMPLEMENT_SCALAR_CASES is now used only by JSON_IMPLEMENT_SCALAR_FAST. Signed-off-by: Niels Lohmann --- include/nlohmann/json.hpp | 10 ++++------ single_include/nlohmann/json.hpp | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0447f8823..33ea53a08 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -5388,8 +5388,7 @@ public: /// @name lexicographical comparison operators /// @{ - // the same-type cases for non-owning scalars, shared by JSON_IMPLEMENT_OPERATOR - // and JSON_IMPLEMENT_SCALAR_FAST + // the same-type cases for non-owning scalars, used by JSON_IMPLEMENT_SCALAR_FAST #define JSON_IMPLEMENT_SCALAR_CASES(op, null_result) \ case value_t::null: \ return (null_result); \ @@ -5411,7 +5410,7 @@ public: // because any negative signed value is smaller than any unsigned value. // Otherwise, the non-negative signed value is cast to unsigned before the // comparison to avoid wraparound. -#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result, deep_result, may_descend) \ +#define JSON_IMPLEMENT_OPERATOR(op, unordered_result, default_result, deep_result, may_descend) \ const auto lhs_type = lhs.type(); \ const auto rhs_type = rhs.type(); \ \ @@ -5548,7 +5547,7 @@ public: JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif - JSON_IMPLEMENT_OPERATOR( ==, true, false, false, + JSON_IMPLEMENT_OPERATOR( ==, false, false, compare_iteratively(lhs, rhs, false) == compare_result::equal, true) #ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP @@ -5562,7 +5561,6 @@ public: // default_result is used if we cannot compare values. In that case, // we compare types. JSON_IMPLEMENT_OPERATOR(<=>, // *NOPAD* - std::partial_ordering::equivalent, std::partial_ordering::unordered, lhs_type <=> rhs_type, // *NOPAD* to_partial_ordering(compare_iteratively(lhs, rhs, false)), true) @@ -5574,7 +5572,7 @@ public: // default_result is used if we cannot compare values. In that case, // we compare types. Note we have to call the operator explicitly, // because MSVC has problems otherwise. - JSON_IMPLEMENT_OPERATOR( <, false, false, operator<(lhs_type, rhs_type), + JSON_IMPLEMENT_OPERATOR( <, false, operator<(lhs_type, rhs_type), compare_iteratively(lhs, rhs, true) == compare_result::less, false) } #endif diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 7fba87d9f..d953b047f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -43156,8 +43156,7 @@ public: /// @name lexicographical comparison operators /// @{ - // the same-type cases for non-owning scalars, shared by JSON_IMPLEMENT_OPERATOR - // and JSON_IMPLEMENT_SCALAR_FAST + // the same-type cases for non-owning scalars, used by JSON_IMPLEMENT_SCALAR_FAST #define JSON_IMPLEMENT_SCALAR_CASES(op, null_result) \ case value_t::null: \ return (null_result); \ @@ -43179,7 +43178,7 @@ public: // because any negative signed value is smaller than any unsigned value. // Otherwise, the non-negative signed value is cast to unsigned before the // comparison to avoid wraparound. -#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result, deep_result, may_descend) \ +#define JSON_IMPLEMENT_OPERATOR(op, unordered_result, default_result, deep_result, may_descend) \ const auto lhs_type = lhs.type(); \ const auto rhs_type = rhs.type(); \ \ @@ -43316,7 +43315,7 @@ public: JSON_HEDLEY_DIAGNOSTIC_PUSH JSON_HEDLEY_PRAGMA(GCC diagnostic ignored "-Wfloat-equal") #endif - JSON_IMPLEMENT_OPERATOR( ==, true, false, false, + JSON_IMPLEMENT_OPERATOR( ==, false, false, compare_iteratively(lhs, rhs, false) == compare_result::equal, true) #ifdef __GNUC__ JSON_HEDLEY_DIAGNOSTIC_POP @@ -43330,7 +43329,6 @@ public: // default_result is used if we cannot compare values. In that case, // we compare types. JSON_IMPLEMENT_OPERATOR(<=>, // *NOPAD* - std::partial_ordering::equivalent, std::partial_ordering::unordered, lhs_type <=> rhs_type, // *NOPAD* to_partial_ordering(compare_iteratively(lhs, rhs, false)), true) @@ -43342,7 +43340,7 @@ public: // default_result is used if we cannot compare values. In that case, // we compare types. Note we have to call the operator explicitly, // because MSVC has problems otherwise. - JSON_IMPLEMENT_OPERATOR( <, false, false, operator<(lhs_type, rhs_type), + JSON_IMPLEMENT_OPERATOR( <, false, operator<(lhs_type, rhs_type), compare_iteratively(lhs, rhs, true) == compare_result::less, false) } #endif