libutil: extend json_avoids_null to floats and enums
Change-Id: Ief80c03ca244fa4d3fd9dc1792f49b8b2802839e
This commit is contained in:
@@ -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 {};
|
||||
|
||||
};
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
Reference in New Issue
Block a user