From 3a69c194e5ef07d047952fbca6340d90370daa43 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Mon, 19 Oct 2026 18:14:26 +0200 Subject: [PATCH] Keep detail::negation out of json_view.hpp's enable_ifs include-what-you-use asks json_view.hpp to include detail/meta/type_traits.hpp for it, which the single header must not do (the amalgamation would duplicate json's internals). The two conditions of value() go through a trait in value.hpp, like the others. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/view/value.hpp | 7 ++++++- include/nlohmann/json_view.hpp | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/nlohmann/detail/view/value.hpp b/include/nlohmann/detail/view/value.hpp index 95139caa2..ca825d775 100644 --- a/include/nlohmann/detail/view/value.hpp +++ b/include/nlohmann/detail/view/value.hpp @@ -12,7 +12,7 @@ #include // int64_t #include // map #include // basic_string -#include // enable_if, is_constructible +#include // decay, enable_if, is_arithmetic, is_constructible, is_integral, is_same #include // unordered_map #include // vector @@ -109,6 +109,11 @@ struct is_string_key : std::is_constructible {}; template struct is_non_bool_arithmetic : conjunction, negation>> {}; +/// the default values of value() other than C strings, which have their own +/// overload (returning string_t) +template +struct is_non_c_string_default : negation::type, const char*>> {}; + /// 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 55e6198b8..5757daed1 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::type, const char*>>::value, int>::type = 0> + template::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::type, const char*>>::value, int>::type = 0> + template::value, int>::type = 0> T value(const json_pointer& ptr, const T& default_value) const { if (NLOHMANN_VIEW_UNLIKELY(!is_structured()))