@@ -354,6 +354,17 @@ struct is_compatible_object_type_impl<true, RealType, CompatibleObjectType>
354354 std::is_constructible<typename RealType::mapped_type, typename CompatibleObjectType::mapped_type>::value;
355355};
356356
357+ template<bool B, class RealType, class CompatibleStringType>
358+ struct is_compatible_string_type_impl : std::false_type {};
359+
360+ template<class RealType, class CompatibleStringType>
361+ struct is_compatible_string_type_impl<true, RealType, CompatibleStringType>
362+ {
363+ static constexpr auto value =
364+ std::is_same<typename RealType::value_type, typename CompatibleStringType::value_type>::value and
365+ std::is_constructible<RealType, CompatibleStringType>::value;
366+ };
367+
357368template<class BasicJsonType, class CompatibleObjectType>
358369struct is_compatible_object_type
359370{
@@ -364,6 +375,15 @@ struct is_compatible_object_type
364375 typename BasicJsonType::object_t, CompatibleObjectType >::value;
365376};
366377
378+ template<class BasicJsonType, class CompatibleStringType>
379+ struct is_compatible_string_type
380+ {
381+ static auto constexpr value = is_compatible_string_type_impl <
382+ conjunction<negation<std::is_same<void, CompatibleStringType>>,
383+ has_value_type<CompatibleStringType>>::value,
384+ typename BasicJsonType::string_t, CompatibleStringType >::value;
385+ };
386+
367387template<typename BasicJsonType, typename T>
368388struct is_basic_json_nested_type
369389{
@@ -980,6 +1000,23 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s)
9801000 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
9811001}
9821002
1003+ template <
1004+ typename BasicJsonType, typename CompatibleStringType,
1005+ enable_if_t <
1006+ is_compatible_string_type<BasicJsonType, CompatibleStringType>::value and
1007+ not std::is_same<typename BasicJsonType::string_t,
1008+ CompatibleStringType>::value,
1009+ int > = 0 >
1010+ void from_json(const BasicJsonType& j, CompatibleStringType& s)
1011+ {
1012+ if (JSON_UNLIKELY(not j.is_string()))
1013+ {
1014+ JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));
1015+ }
1016+
1017+ s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
1018+ }
1019+
9831020template<typename BasicJsonType>
9841021void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val)
9851022{
@@ -1324,6 +1361,16 @@ struct external_constructor<value_t::string>
13241361 j.m_value = std::move(s);
13251362 j.assert_invariant();
13261363 }
1364+
1365+ template<typename BasicJsonType, typename CompatibleStringType,
1366+ enable_if_t<not std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
1367+ int> = 0>
1368+ static void construct(BasicJsonType& j, const CompatibleStringType& str)
1369+ {
1370+ j.m_type = value_t::string;
1371+ j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
1372+ j.assert_invariant();
1373+ }
13271374};
13281375
13291376template<>
@@ -13588,9 +13635,9 @@ class basic_json
1358813635 not detail::is_basic_json<ValueType>::value
1358913636#ifndef _MSC_VER // fix for issue #167 operator<< ambiguity under VS2015
1359013637 and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
13591- #endif
13592- #if defined(JSON_HAS_CPP_17)
13638+ #if defined(JSON_HAS_CPP_17) && _MSC_VER <= 1914
1359313639 and not std::is_same<ValueType, typename std::string_view>::value
13640+ #endif
1359413641#endif
1359513642 , int >::type = 0 >
1359613643 operator ValueType() const
0 commit comments