libutil: extend json_avoids_null to floats and enums

Change-Id: Ief80c03ca244fa4d3fd9dc1792f49b8b2802839e
This commit is contained in:
eldritch horrors
2025-03-23 20:42:39 +00:00
parent 19d7c8352e
commit f7d1a6ba8b
3 changed files with 5 additions and 14 deletions
-6
View File
@@ -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<DeprecatedFeature> : std::true_type {};
};
@@ -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<ExperimentalFeature> : std::true_type {};
};
+5 -2
View File
@@ -3,6 +3,7 @@
#include "lix/libutil/json.hh"
#include <list>
#include <type_traits>
namespace nix {
@@ -41,10 +42,12 @@ template<typename T>
struct json_avoids_null;
/**
* Handle numbers in default impl
* Handle numbers and enums in default impl
*/
template<typename T>
struct json_avoids_null : std::bool_constant<std::is_integral<T>::value> {};
struct json_avoids_null
: std::bool_constant<std::is_integral_v<T> || std::is_floating_point_v<T> || std::is_enum_v<T>>
{};
template<>
struct json_avoids_null<std::nullptr_t> : std::false_type {};