--- ext/json/json.hpp 2018-05-11 20:40:22 UTC +++ ext/json/json.hpp @@ -353,6 +353,16 @@ struct is_compatible_object_type_impl::value; }; +template +struct is_compatible_string_type_impl : std::false_type {}; + +template +struct is_compatible_string_type_impl +{ + static constexpr auto value = + std::is_same::value; +}; + template struct is_compatible_object_type { @@ -363,6 +373,15 @@ struct is_compatible_object_type typename BasicJsonType::object_t, CompatibleObjectType >::value; }; +template +struct is_compatible_string_type +{ + static auto constexpr value = is_compatible_string_type_impl < + conjunction>, + has_value_type>::value, + typename BasicJsonType::string_t, CompatibleStringType >::value; +}; + template struct is_basic_json_nested_type { @@ -974,6 +993,25 @@ void from_json(const BasicJsonType& j, typename BasicJ { JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); } + s = *j.template get_ptr(); +} + +template < + typename BasicJsonType, typename CompatibleStringType, + enable_if_t < + is_compatible_string_type::value and + not std::is_same::value and + std::is_constructible < + BasicJsonType, typename CompatibleStringType::value_type >::value, + int > = 0 > +void from_json(const BasicJsonType& j, CompatibleStringType& s) +{ + if (JSON_UNLIKELY(not j.is_string())) + { + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()))); + } + s = *j.template get_ptr(); }