From 897aaa0787cf59eb22c7e84ca9620ba5299f6102 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 19 Oct 2026 17:53:02 +0200 Subject: [PATCH] Write the negated enable_if conditions of json_view with negation<> With a ! or && in the condition, astyle spaces the whole template header (template < ... >); detail::negation and a named trait keep it compact, as the library writes such conditions elsewhere. From gregmarr's review of #5630. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/value.hpp | 5 +++++ include/nlohmann/json_view.hpp | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/nlohmann/detail/view/value.hpp b/include/nlohmann/detail/view/value.hpp index 5684ab38e..95139caa2 100644 --- a/include/nlohmann/detail/view/value.hpp +++ b/include/nlohmann/detail/view/value.hpp @@ -104,6 +104,11 @@ Map map_value(const View& v) template struct is_string_key : std::is_constructible {}; +/// the arithmetic types arithmetic_value() converts to (bool has its own +/// conversion) +template +struct is_non_bool_arithmetic : conjunction, negation>> {}; + /// whether View::get() converts to T without materialize(); get_to() /// assigns these, and passes the others to from_json template diff --git a/include/nlohmann/json_view.hpp b/include/nlohmann/json_view.hpp index d754a914b..55e6198b8 100644 --- a/include/nlohmann/json_view.hpp +++ b/include/nlohmann/json_view.hpp @@ -365,7 +365,7 @@ class basic_json_view /// the member with this key converted to T, or the default value if there /// is no such member (the first one, should the key occur more than /// once). Throws type_error.306 if this is not an object. - template < typename T, typename std::enable_if < !std::is_same::type, const char*>::value, int >::type = 0 > + template::type, const char*>>::value, int>::type = 0> T value(string_view_t key, const T& default_value) const { if (NLOHMANN_VIEW_UNLIKELY(!is_object())) @@ -384,7 +384,7 @@ class basic_json_view /// the value a JSON pointer refers to converted to T, or the default /// value if the pointer cannot be resolved. Throws type_error.306 if this /// is neither an object nor an array. - template < typename T, typename std::enable_if < !std::is_same::type, const char*>::value, int >::type = 0 > + template::type, const char*>>::value, int>::type = 0> T value(const json_pointer& ptr, const T& default_value) const { if (NLOHMANN_VIEW_UNLIKELY(!is_structured())) @@ -627,7 +627,7 @@ class basic_json_view return (m_node->flags & detail::view::node_flags::is_true) != 0; } - template < typename T, typename std::enable_if < std::is_arithmetic::value && !std::is_same::value, int >::type = 0 > + template::value, int>::type = 0> NLOHMANN_VIEW_ALWAYS_INLINE T get_impl(detail::view::value_tag /*unused*/, detail::priority_tag<2> /*unused*/) const { if (NLOHMANN_VIEW_UNLIKELY(m_node == nullptr))