From a87c1885cb784ea5b884ed6dd1c96e39b7b4ec64 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Thu, 28 Jul 2022 21:52:23 +0200 Subject: [PATCH] Re-add value_type detection to distinguish string types (#3604) * Re-add value_type detection to is_constructible_string_type trait * Add value_type detection to from_json for strings --- include/nlohmann/detail/conversions/from_json.hpp | 1 + include/nlohmann/detail/meta/type_traits.hpp | 6 ++++-- single_include/nlohmann/json.hpp | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index f1df783e5..af2abddbf 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -117,6 +117,7 @@ template < typename BasicJsonType, typename StringType, enable_if_t < std::is_assignable::value + && is_detected_exact::value && !std::is_same::value && !is_json_ref::value, int > = 0 > inline void from_json(const BasicJsonType& j, StringType& s) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 11bf3c12a..796d5b0cd 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -363,8 +363,10 @@ struct is_constructible_string_type #endif static constexpr auto value = - is_constructible::value; + conjunction < + is_constructible, + is_detected_exact>::value; }; template diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 36481050e..78b41822e 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3651,8 +3651,10 @@ struct is_constructible_string_type #endif static constexpr auto value = - is_constructible::value; + conjunction < + is_constructible, + is_detected_exact>::value; }; template @@ -4478,6 +4480,7 @@ template < typename BasicJsonType, typename StringType, enable_if_t < std::is_assignable::value + && is_detected_exact::value && !std::is_same::value && !is_json_ref::value, int > = 0 > inline void from_json(const BasicJsonType& j, StringType& s)