Skip to content

Commit

Permalink
Re-add value_type detection to distinguish string types (#3604)
Browse files Browse the repository at this point in the history
* Re-add value_type detection to is_constructible_string_type trait

* Add value_type detection to from_json for strings
  • Loading branch information
falbrechtskirchinger authored Jul 28, 2022
1 parent a714381 commit a87c188
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/nlohmann/detail/conversions/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ template <
typename BasicJsonType, typename StringType,
enable_if_t <
std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
&& is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
&& !std::is_same<typename BasicJsonType::string_t, StringType>::value
&& !is_json_ref<StringType>::value, int > = 0 >
inline void from_json(const BasicJsonType& j, StringType& s)
Expand Down
6 changes: 4 additions & 2 deletions include/nlohmann/detail/meta/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ struct is_constructible_string_type
#endif

static constexpr auto value =
is_constructible<laundered_type,
typename BasicJsonType::string_t>::value;
conjunction <
is_constructible<laundered_type, typename BasicJsonType::string_t>,
is_detected_exact<typename BasicJsonType::string_t::value_type,
value_type_t, laundered_type >>::value;
};

template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
Expand Down
7 changes: 5 additions & 2 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3651,8 +3651,10 @@ struct is_constructible_string_type
#endif

static constexpr auto value =
is_constructible<laundered_type,
typename BasicJsonType::string_t>::value;
conjunction <
is_constructible<laundered_type, typename BasicJsonType::string_t>,
is_detected_exact<typename BasicJsonType::string_t::value_type,
value_type_t, laundered_type >>::value;
};

template<typename BasicJsonType, typename CompatibleArrayType, typename = void>
Expand Down Expand Up @@ -4478,6 +4480,7 @@ template <
typename BasicJsonType, typename StringType,
enable_if_t <
std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
&& is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
&& !std::is_same<typename BasicJsonType::string_t, StringType>::value
&& !is_json_ref<StringType>::value, int > = 0 >
inline void from_json(const BasicJsonType& j, StringType& s)
Expand Down

0 comments on commit a87c188

Please sign in to comment.