From f7d1a6ba8b97a83c4d7a7dfe642ffbd00d6f4bcc Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sun, 23 Mar 2025 15:36:11 +0100 Subject: [PATCH] libutil: extend json_avoids_null to floats and enums Change-Id: Ief80c03ca244fa4d3fd9dc1792f49b8b2802839e --- lix/libutil/deprecated-features-json.hh | 6 ------ lix/libutil/experimental-features-json.hh | 6 ------ lix/libutil/json-utils.hh | 7 +++++-- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lix/libutil/deprecated-features-json.hh b/lix/libutil/deprecated-features-json.hh index f3992e64b..913c437cd 100644 --- a/lix/libutil/deprecated-features-json.hh +++ b/lix/libutil/deprecated-features-json.hh @@ -20,10 +20,4 @@ JSON documentDeprecatedFeatures(); void to_json(JSON &, const DeprecatedFeature &); void from_json(const JSON &, DeprecatedFeature &); -/** - * It is always rendered as a string - */ -template<> -struct json_avoids_null : std::true_type {}; - }; diff --git a/lix/libutil/experimental-features-json.hh b/lix/libutil/experimental-features-json.hh index 8a31d4548..8329c7e41 100644 --- a/lix/libutil/experimental-features-json.hh +++ b/lix/libutil/experimental-features-json.hh @@ -20,10 +20,4 @@ JSON documentExperimentalFeatures(); void to_json(JSON &, const ExperimentalFeature &); void from_json(const JSON &, ExperimentalFeature &); -/** - * It is always rendered as a string - */ -template<> -struct json_avoids_null : std::true_type {}; - }; diff --git a/lix/libutil/json-utils.hh b/lix/libutil/json-utils.hh index bae902892..7f75f1baa 100644 --- a/lix/libutil/json-utils.hh +++ b/lix/libutil/json-utils.hh @@ -3,6 +3,7 @@ #include "lix/libutil/json.hh" #include +#include namespace nix { @@ -41,10 +42,12 @@ template struct json_avoids_null; /** - * Handle numbers in default impl + * Handle numbers and enums in default impl */ template -struct json_avoids_null : std::bool_constant::value> {}; +struct json_avoids_null + : std::bool_constant || std::is_floating_point_v || std::is_enum_v> +{}; template<> struct json_avoids_null : std::false_type {};